Search in sources :

Example 6 with BaseAccount

use of com.fsck.k9.BaseAccount 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);
        }
    }
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) BaseAccount(com.fsck.k9.BaseAccount) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) SearchAccount(com.fsck.k9.search.SearchAccount) MenuItem(android.view.MenuItem)

Example 7 with BaseAccount

use of com.fsck.k9.BaseAccount 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);
        }
    }
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) BaseAccount(com.fsck.k9.BaseAccount) MessagingController(com.fsck.k9.controller.MessagingController) SearchAccount(com.fsck.k9.search.SearchAccount)

Example 8 with BaseAccount

use of com.fsck.k9.BaseAccount 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;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) Toast(android.widget.Toast) LocalSearch(com.fsck.k9.search.LocalSearch) SearchAccount(com.fsck.k9.search.SearchAccount)

Example 9 with BaseAccount

use of com.fsck.k9.BaseAccount 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();
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) Intent(android.content.Intent) Parcelable(android.os.Parcelable) SearchAccount(com.fsck.k9.search.SearchAccount)

Aggregations

BaseAccount (com.fsck.k9.BaseAccount)9 Account (com.fsck.k9.Account)6 SearchAccount (com.fsck.k9.search.SearchAccount)6 LocalSearch (com.fsck.k9.search.LocalSearch)3 Intent (android.content.Intent)2 MessagingController (com.fsck.k9.controller.MessagingController)2 PendingIntent (android.app.PendingIntent)1 Parcelable (android.os.Parcelable)1 MenuItem (android.view.MenuItem)1 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)1 ListView (android.widget.ListView)1 RemoteViews (android.widget.RemoteViews)1 Toast (android.widget.Toast)1 AccountStats (com.fsck.k9.AccountStats)1 UnreadWidgetConfiguration (com.fsck.k9.activity.UnreadWidgetConfiguration)1 ArrayList (java.util.ArrayList)1