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

This commit is contained in:
Stefan Niedermann 2021-05-17 10:02:54 +02:00
parent a7c62f7ede
commit 80c50395f0

View file

@ -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<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();
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);