use of com.fsck.k9.search.SearchAccount in project k-9 by k9mail.
the class Accounts method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle(R.string.accounts_context_menu_title);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
BaseAccount account = mAdapter.getItem(info.position);
if ((account instanceof Account) && !((Account) account).isEnabled()) {
getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
} else {
getMenuInflater().inflate(R.menu.accounts_context, menu);
}
if (account instanceof SearchAccount) {
for (int i = 0; i < menu.size(); i++) {
android.view.MenuItem item = menu.getItem(i);
item.setVisible(false);
}
} else {
EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
menu.findItem(R.id.move_up).setEnabled(false);
} else {
menu.findItem(R.id.move_up).setEnabled(true);
}
if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
menu.findItem(R.id.move_down).setEnabled(false);
} else {
menu.findItem(R.id.move_down).setEnabled(true);
}
}
}
use of com.fsck.k9.search.SearchAccount in project k-9 by k9mail.
the class Accounts method refresh.
private void refresh() {
accounts.clear();
accounts.addAll(Preferences.getPreferences(this).getAccounts());
// see if we should show the welcome message
// if (accounts.length < 1) {
// WelcomeMessage.showWelcomeMessage(this);
// finish();
// }
List<BaseAccount> newAccounts;
if (!K9.isHideSpecialAccounts() && accounts.size() > 0) {
if (mUnifiedInboxAccount == null || mAllMessagesAccount == null) {
createSpecialAccounts();
}
newAccounts = new ArrayList<BaseAccount>(accounts.size() + SPECIAL_ACCOUNTS_COUNT);
newAccounts.add(mUnifiedInboxAccount);
newAccounts.add(mAllMessagesAccount);
} else {
newAccounts = new ArrayList<BaseAccount>(accounts.size());
}
newAccounts.addAll(accounts);
mAdapter = new AccountsAdapter(newAccounts);
getListView().setAdapter(mAdapter);
if (!newAccounts.isEmpty()) {
mHandler.progress(Window.PROGRESS_START);
}
pendingWork.clear();
mHandler.refreshTitle();
MessagingController controller = MessagingController.getInstance(getApplication());
for (BaseAccount account : newAccounts) {
pendingWork.put(account, "true");
if (account instanceof Account) {
Account realAccount = (Account) account;
controller.getAccountStats(this, realAccount, mListener);
} else if (K9.countSearchMessages() && account instanceof SearchAccount) {
final SearchAccount searchAccount = (SearchAccount) account;
controller.getSearchAccountStats(searchAccount, mListener);
}
}
}
use of com.fsck.k9.search.SearchAccount in project k-9 by k9mail.
the class Accounts method onOpenAccount.
/**
* Show that account's inbox or folder-list
* or return false if the account is not available.
* @param account the account to open ({@link SearchAccount} or {@link Account})
* @return false if unsuccessful
*/
private boolean onOpenAccount(BaseAccount account) {
if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount) account;
MessageList.actionDisplaySearch(this, searchAccount.getRelatedSearch(), false, false);
} else {
Account realAccount = (Account) account;
if (!realAccount.isEnabled()) {
onActivateAccount(realAccount);
return false;
} else if (!realAccount.isAvailable(this)) {
String toastText = getString(R.string.account_unavailable, account.getDescription());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show();
Timber.i("refusing to open account that is not available");
return false;
}
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
FolderList.actionHandleAccount(this, realAccount);
} else {
LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
search.addAllowedFolder(realAccount.getAutoExpandFolderName());
search.addAccountUuid(realAccount.getUuid());
MessageList.actionDisplaySearch(this, search, false, true);
}
}
return true;
}
use of com.fsck.k9.search.SearchAccount in project k-9 by k9mail.
the class LauncherShortcuts method onAccountSelected.
@Override
protected void onAccountSelected(BaseAccount account) {
Intent shortcutIntent = null;
if (account instanceof SearchAccount) {
SearchAccount searchAccount = (SearchAccount) account;
shortcutIntent = MessageList.shortcutIntent(this, searchAccount.getId());
} else {
shortcutIntent = FolderList.actionHandleAccountIntent(this, (Account) account, true);
}
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
String description = account.getDescription();
if (description == null || description.isEmpty()) {
description = account.getEmail();
}
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, intent);
finish();
}
Aggregations