Search in sources :

Example 1 with UserListItem

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

the class ManageAccountsActivity method run.

@Override
public void run(AccountManagerFuture<Boolean> future) {
    if (future.isDone()) {
        // after remove account
        Account account = new Account(accountName, MainApp.getAccountType(this));
        if (!accountManager.exists(account)) {
            // Cancel transfers of the removed account
            if (mUploaderBinder != null) {
                mUploaderBinder.cancel(account);
            }
            if (mDownloaderBinder != null) {
                mDownloaderBinder.cancel(account);
            }
        }
        User user = getUserAccountManager().getUser();
        if (user.isAnonymous()) {
            String accountName = "";
            Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
            if (accounts.length != 0) {
                accountName = accounts[0].name;
            }
            accountManager.setCurrentOwnCloudAccount(accountName);
        }
        List<UserListItem> userListItemArray = getUserListItems();
        if (userListItemArray.size() > SINGLE_ACCOUNT) {
            userListAdapter = new UserListAdapter(this, accountManager, userListItemArray, this, multipleAccountsSupported, false);
            recyclerView.setAdapter(userListAdapter);
        } else {
            onBackPressed();
        }
    }
}
Also used : Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) User(com.nextcloud.client.account.User) UserListItem(com.owncloud.android.ui.adapter.UserListItem) UserListAdapter(com.owncloud.android.ui.adapter.UserListAdapter)

Example 2 with UserListItem

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

the class ManageAccountsActivity method performAccountRemoval.

private void performAccountRemoval(User user) {
    // disable account in recycler view
    for (int i = 0; i < userListAdapter.getItemCount(); i++) {
        UserListItem item = userListAdapter.getItem(i);
        if (item != null && item.getUser().getAccountName().equalsIgnoreCase(user.getAccountName())) {
            item.setEnabled(false);
            break;
        }
        userListAdapter.notifyDataSetChanged();
    }
    // store pending account removal
    ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
    arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), PENDING_FOR_REMOVAL, String.valueOf(true));
    // Cancel transfers
    if (mUploaderBinder != null) {
        mUploaderBinder.cancel(user.toPlatformAccount());
    }
    if (mDownloaderBinder != null) {
        mDownloaderBinder.cancel(user.toPlatformAccount());
    }
    backgroundJobManager.startAccountRemovalJob(user.getAccountName(), false);
    // immediately select a new account
    List<User> users = accountManager.getAllUsers();
    String newAccountName = "";
    for (User u : users) {
        if (!u.getAccountName().equalsIgnoreCase(u.getAccountName())) {
            newAccountName = u.getAccountName();
            break;
        }
    }
    if (newAccountName.isEmpty()) {
        Log_OC.d(TAG, "new account set to null");
        accountManager.resetOwnCloudAccount();
    } else {
        Log_OC.d(TAG, "new account set to: " + newAccountName);
        accountManager.setCurrentOwnCloudAccount(newAccountName);
    }
    // only one to be (deleted) account remaining
    if (users.size() < MIN_MULTI_ACCOUNT_SIZE) {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, true);
        resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, true);
        setResult(RESULT_OK, resultIntent);
        super.onBackPressed();
    }
}
Also used : User(com.nextcloud.client.account.User) UserListItem(com.owncloud.android.ui.adapter.UserListItem) ArbitraryDataProvider(com.owncloud.android.datamodel.ArbitraryDataProvider) Intent(android.content.Intent)

Example 3 with UserListItem

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

the class MultipleAccountsDialog method getAccountListItems.

/**
 * creates the account list items list including the add-account action in case
 * multiaccount_support is enabled.
 *
 * @return list of account list items
 */
private List<UserListItem> getAccountListItems() {
    List<User> users = accountManager.getAllUsers();
    List<UserListItem> adapterUserList = new ArrayList<>(users.size());
    for (User user : users) {
        adapterUserList.add(new UserListItem(user));
    }
    return adapterUserList;
}
Also used : User(com.nextcloud.client.account.User) ArrayList(java.util.ArrayList) UserListItem(com.owncloud.android.ui.adapter.UserListItem)

Example 4 with UserListItem

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

the class ManageAccountsActivity method getUserListItems.

private List<UserListItem> getUserListItems() {
    List<User> users = accountManager.getAllUsers();
    List<UserListItem> userListItems = new ArrayList<>(users.size());
    for (User user : users) {
        boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(user, PENDING_FOR_REMOVAL);
        userListItems.add(new UserListItem(user, !pendingForRemoval));
    }
    if (getResources().getBoolean(R.bool.multiaccount_support)) {
        userListItems.add(new UserListItem());
    }
    return userListItems;
}
Also used : User(com.nextcloud.client.account.User) ArrayList(java.util.ArrayList) UserListItem(com.owncloud.android.ui.adapter.UserListItem)

Aggregations

User (com.nextcloud.client.account.User)4 UserListItem (com.owncloud.android.ui.adapter.UserListItem)4 ArrayList (java.util.ArrayList)2 Account (android.accounts.Account)1 Intent (android.content.Intent)1 ArbitraryDataProvider (com.owncloud.android.datamodel.ArbitraryDataProvider)1 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)1 UserListAdapter (com.owncloud.android.ui.adapter.UserListAdapter)1