Эх сурвалжийг харах

3rd-party-apps trashbin: Use SessionMixin to switch to targetUser

Stefan Niedermann 4 жил өмнө
parent
commit
80c50395f0

+ 10 - 5
src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java

@@ -37,6 +37,7 @@ import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.AppPreferences;
+import com.nextcloud.java.util.Optional;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.databinding.TrashbinActivityBinding;
 import com.owncloud.android.databinding.TrashbinActivityBinding;
 import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
 import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
@@ -85,17 +86,21 @@ public class TrashbinActivity extends DrawerActivity implements
     @Override
     @Override
     protected void onCreate(Bundle savedInstanceState) {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
-        final User user = accountProvider.getUser();
+        final User currentUser = getUser().orElse(accountProvider.getUser());
         final String targetAccount = getIntent().getStringExtra(ARG_TARGET_ACCOUNT_NAME);
         final String targetAccount = getIntent().getStringExtra(ARG_TARGET_ACCOUNT_NAME);
-        if (!user.nameEquals(targetAccount)) {
-            if (!getUserAccountManager().setCurrentOwnCloudAccount(targetAccount)) {
+        if (targetAccount != null && !currentUser.nameEquals(targetAccount)) {
+            final Optional<User> targetUser = getUserAccountManager().getUser(targetAccount);
+            if (targetUser.isPresent()) {
+                setUser(targetUser.get());
+            } else {
                 Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show();
                 Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show();
                 finish();
                 finish();
                 return;
                 return;
             }
             }
         }
         }
 
 
-        final RemoteTrashbinRepository trashRepository = new RemoteTrashbinRepository(user, clientFactory);
+        final RemoteTrashbinRepository trashRepository =
+            new RemoteTrashbinRepository(getUser().orElse(accountProvider.getUser()), clientFactory);
         trashbinPresenter = new TrashbinPresenter(trashRepository, this);
         trashbinPresenter = new TrashbinPresenter(trashRepository, this);
 
 
         binding = TrashbinActivityBinding.inflate(getLayoutInflater());
         binding = TrashbinActivityBinding.inflate(getLayoutInflater());
@@ -130,7 +135,7 @@ public class TrashbinActivity extends DrawerActivity implements
             getStorageManager(),
             getStorageManager(),
             preferences,
             preferences,
             this,
             this,
-            getUserAccountManager().getUser()
+            getUser().orElse(accountProvider.getUser())
         );
         );
         recyclerView.setAdapter(trashbinListAdapter);
         recyclerView.setAdapter(trashbinListAdapter);
         recyclerView.setHasFixedSize(true);
         recyclerView.setHasFixedSize(true);