use of com.owncloud.android.usecases.CancelUploadFromAccountUseCase in project android by owncloud.
the class ManageAccountsActivity method run.
/**
* Callback executed after the {@link AccountManager} removed an account
*
* @param future Result of the removal; future.getResult() is true if account was removed correctly.
*/
@Override
public void run(AccountManagerFuture<Boolean> future) {
if (future != null && future.isDone()) {
Account account = new Account(mAccountBeingRemoved, MainApp.Companion.getAccountType());
if (!AccountUtils.exists(account.name, MainApp.Companion.getAppContext())) {
// Cancel transfers of the removed account
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
CancelUploadFromAccountUseCase cancelUploadFromAccountUseCase = new CancelUploadFromAccountUseCase(WorkManager.getInstance(getBaseContext()));
cancelUploadFromAccountUseCase.execute(new CancelUploadFromAccountUseCase.Params(account.name));
}
mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
AccountManager am = AccountManager.get(this);
if (am.getAccountsByType(MainApp.Companion.getAccountType()).length == 0) {
// Show create account screen if there isn't any account
am.addAccount(MainApp.Companion.getAccountType(), null, null, null, this, null, null);
} else {
// at least one account left
if (AccountUtils.getCurrentOwnCloudAccount(this) == null) {
// current account was removed - set another as current
String accountName = "";
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.Companion.getAccountType());
if (accounts.length != 0) {
accountName = accounts[0].name;
}
AccountUtils.setCurrentOwnCloudAccount(this, accountName);
}
}
}
}
Aggregations