Search in sources :

Example 1 with AccountListAdapter

use of com.owncloud.android.ui.adapter.AccountListAdapter in project android by nextcloud.

the class ManageAccountsActivity method createAccount.

@Override
public void createAccount() {
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addAccount(MainApp.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() {

        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            if (future != null) {
                try {
                    Bundle result = future.getResult();
                    String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name);
                    mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck);
                    mListView.setAdapter(mAccountListAdapter);
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            mAccountListAdapter.notifyDataSetChanged();
                        }
                    });
                } catch (OperationCanceledException e) {
                    Log_OC.d(TAG, "Account creation canceled");
                } catch (Exception e) {
                    Log_OC.e(TAG, "Account creation finished in exception: ", e);
                }
            }
        }
    }, mHandler);
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter) OperationCanceledException(android.accounts.OperationCanceledException)

Example 2 with AccountListAdapter

use of com.owncloud.android.ui.adapter.AccountListAdapter in project android by owncloud.

the class ManageAccountsActivity method createAccount.

@Override
public void createAccount() {
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addAccount(MainApp.Companion.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() {

        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            if (future != null) {
                try {
                    Bundle result = future.getResult();
                    String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name);
                    mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck);
                    mListView.setAdapter(mAccountListAdapter);
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            mAccountListAdapter.notifyDataSetChanged();
                        }
                    });
                } catch (OperationCanceledException e) {
                    Timber.e(e, "Account creation canceled");
                } catch (Exception e) {
                    Timber.e(e, "Account creation finished in exception");
                }
            }
        }
    }, mHandler);
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter) OperationCanceledException(android.accounts.OperationCanceledException)

Example 3 with AccountListAdapter

use of com.owncloud.android.ui.adapter.AccountListAdapter 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)

Example 4 with AccountListAdapter

use of com.owncloud.android.ui.adapter.AccountListAdapter in project android by owncloud.

the class ManageAccountsActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
    mListView.setAdapter(mAccountListAdapter);
}
Also used : AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter)

Aggregations

AccountListAdapter (com.owncloud.android.ui.adapter.AccountListAdapter)4 AccountManager (android.accounts.AccountManager)3 OperationCanceledException (android.accounts.OperationCanceledException)2 Bundle (android.os.Bundle)2 Account (android.accounts.Account)1 CancelUploadFromAccountUseCase (com.owncloud.android.usecases.CancelUploadFromAccountUseCase)1