Search in sources :

Example 1 with CancelUploadFromAccountUseCase

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);
            }
        }
    }
}
Also used : CancelUploadFromAccountUseCase(com.owncloud.android.usecases.CancelUploadFromAccountUseCase) Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter)

Aggregations

Account (android.accounts.Account)1 AccountManager (android.accounts.AccountManager)1 AccountListAdapter (com.owncloud.android.ui.adapter.AccountListAdapter)1 CancelUploadFromAccountUseCase (com.owncloud.android.usecases.CancelUploadFromAccountUseCase)1