diff --git a/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java b/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java index 274e43fe25..3503c40321 100644 --- a/src/main/java/com/owncloud/android/ui/trashbin/TrashbinActivity.java +++ b/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.network.ClientFactory; import com.nextcloud.client.preferences.AppPreferences; +import com.nextcloud.java.util.Optional; import com.owncloud.android.R; import com.owncloud.android.databinding.TrashbinActivityBinding; import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile; @@ -85,17 +86,21 @@ public class TrashbinActivity extends DrawerActivity implements @Override protected void onCreate(Bundle 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); - if (!user.nameEquals(targetAccount)) { - if (!getUserAccountManager().setCurrentOwnCloudAccount(targetAccount)) { + if (targetAccount != null && !currentUser.nameEquals(targetAccount)) { + final Optional targetUser = getUserAccountManager().getUser(targetAccount); + if (targetUser.isPresent()) { + setUser(targetUser.get()); + } else { Toast.makeText(this, R.string.associated_account_not_found, Toast.LENGTH_LONG).show(); finish(); return; } } - final RemoteTrashbinRepository trashRepository = new RemoteTrashbinRepository(user, clientFactory); + final RemoteTrashbinRepository trashRepository = + new RemoteTrashbinRepository(getUser().orElse(accountProvider.getUser()), clientFactory); trashbinPresenter = new TrashbinPresenter(trashRepository, this); binding = TrashbinActivityBinding.inflate(getLayoutInflater()); @@ -130,7 +135,7 @@ public class TrashbinActivity extends DrawerActivity implements getStorageManager(), preferences, this, - getUserAccountManager().getUser() + getUser().orElse(accountProvider.getUser()) ); recyclerView.setAdapter(trashbinListAdapter); recyclerView.setHasFixedSize(true);