use of com.owncloud.android.ui.adapter.AccountListItem 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(mAccountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, MainApp.getAppContext())) {
// Cancel transfers of the removed account
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
}
if (AccountUtils.getCurrentOwnCloudAccount(this) == null) {
String accountName = "";
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
if (accounts.length != 0) {
accountName = accounts[0].name;
}
AccountUtils.setCurrentOwnCloudAccount(this, accountName);
}
ArrayList<AccountListItem> accountListItemArray = getAccountListItems();
if (accountListItemArray.size() > 1) {
mAccountListAdapter = new AccountListAdapter(this, accountListItemArray, mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
} else {
onBackPressed();
}
}
}
use of com.owncloud.android.ui.adapter.AccountListItem in project android by nextcloud.
the class ManageAccountsActivity 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 ArrayList<AccountListItem> getAccountListItems() {
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
ArrayList<AccountListItem> adapterAccountList = new ArrayList<>(accountList.length);
for (Account account : accountList) {
boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account, PENDING_FOR_REMOVAL);
adapterAccountList.add(new AccountListItem(account, !pendingForRemoval));
}
// Add Create Account item at the end of account list if multi-account is enabled
if (getResources().getBoolean(R.bool.multiaccount_support)) {
adapterAccountList.add(new AccountListItem());
}
return adapterAccountList;
}
use of com.owncloud.android.ui.adapter.AccountListItem in project android by owncloud.
the class ManageAccountsActivity 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 ArrayList<AccountListItem> getAccountListItems() {
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
ArrayList<AccountListItem> adapterAccountList = new ArrayList<AccountListItem>(accountList.length);
for (Account account : accountList) {
adapterAccountList.add(new AccountListItem(account));
}
// Add Create Account item at the end of account list if multi-account is enabled
if (getResources().getBoolean(R.bool.multiaccount_support)) {
adapterAccountList.add(new AccountListItem());
}
return adapterAccountList;
}
use of com.owncloud.android.ui.adapter.AccountListItem in project android by nextcloud.
the class ManageAccountsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(this, R.drawable.ic_account_circle_white_18dp));
int tint = ThemeUtils.primaryColor();
DrawableCompat.setTint(mTintedCheck, tint);
setContentView(R.layout.accounts_layout);
mListView = (ListView) findViewById(R.id.account_list);
setupToolbar();
updateActionBarTitleAndHomeButtonByString(getResources().getString(R.string.prefs_manage_accounts));
Account[] accountList = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
mOriginalAccounts = DisplayUtils.toAccountNameSet(Arrays.asList(accountList));
mOriginalCurrentAccount = AccountUtils.getCurrentOwnCloudAccount(this).name;
setAccount(AccountUtils.getCurrentOwnCloudAccount(this));
onAccountSet(false);
arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
mAccountListAdapter = new AccountListAdapter(this, getAccountListItems(), mTintedCheck);
mListView.setAdapter(mAccountListAdapter);
final Intent intent = new Intent(this, UserInfoActivity.class);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AccountListItem item = mAccountListAdapter.getItem(position);
if (item != null && item.isEnabled()) {
Account account = item.getAccount();
intent.putExtra(UserInfoActivity.KEY_ACCOUNT, Parcels.wrap(account));
try {
OwnCloudAccount oca = new OwnCloudAccount(account, MainApp.getAppContext());
intent.putExtra(KEY_DISPLAY_NAME, oca.getDisplayName());
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
Log_OC.d(TAG, "Failed to find NC account");
}
startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
}
}
});
initializeComponentGetters();
}
use of com.owncloud.android.ui.adapter.AccountListItem in project android by nextcloud.
the class ManageAccountsActivity method performAccountRemoval.
private void performAccountRemoval(Account account) {
// disable account in list view
for (int i = 0; i < mAccountListAdapter.getCount(); i++) {
AccountListItem item = mAccountListAdapter.getItem(i);
if (item != null && item.getAccount().equals(account)) {
item.setEnabled(false);
break;
}
mAccountListAdapter.notifyDataSetChanged();
}
// store pending account removal
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
arbitraryDataProvider.storeOrUpdateKeyValue(account.name, PENDING_FOR_REMOVAL, String.valueOf(true));
// Cancel transfers
if (mUploaderBinder != null) {
mUploaderBinder.cancel(account);
}
if (mDownloaderBinder != null) {
mDownloaderBinder.cancel(account);
}
// schedule job
PersistableBundleCompat bundle = new PersistableBundleCompat();
bundle.putString(AccountRemovalJob.ACCOUNT, account.name);
new JobRequest.Builder(AccountRemovalJob.TAG).startNow().setExtras(bundle).setUpdateCurrent(false).build().schedule();
// immediately select a new account
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
String newAccountName = "";
for (Account acc : accounts) {
if (!account.name.equalsIgnoreCase(acc.name)) {
newAccountName = acc.name;
break;
}
}
if (newAccountName.isEmpty()) {
Log_OC.d(TAG, "new account set to null");
AccountUtils.resetOwnCloudAccount(this);
} else {
Log_OC.d(TAG, "new account set to: " + newAccountName);
AccountUtils.setCurrentOwnCloudAccount(this, newAccountName);
}
// only one to be (deleted) account remaining
if (accounts.length < 2) {
Intent resultIntent = new Intent();
resultIntent.putExtra(KEY_ACCOUNT_LIST_CHANGED, true);
resultIntent.putExtra(KEY_CURRENT_ACCOUNT_CHANGED, true);
setResult(RESULT_OK, resultIntent);
super.onBackPressed();
}
}
Aggregations