Search in sources :

Example 16 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class FolderList method onOpenFolder.

private void onOpenFolder(String folder) {
    LocalSearch search = new LocalSearch(folder);
    search.addAccountUuid(mAccount.getUuid());
    search.addAllowedFolder(folder);
    MessageList.actionDisplaySearch(this, search, false, false);
}
Also used : LocalSearch(com.fsck.k9.search.LocalSearch)

Example 17 with LocalSearch

use of com.fsck.k9.search.LocalSearch in project k-9 by k9mail.

the class MessagingController method getSearchAccountStatsSynchronous.

public AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount, final MessagingListener listener) {
    Preferences preferences = Preferences.getPreferences(context);
    LocalSearch search = searchAccount.getRelatedSearch();
    // Collect accounts that belong to the search
    String[] accountUuids = search.getAccountUuids();
    List<Account> accounts;
    if (search.searchAllAccounts()) {
        accounts = preferences.getAccounts();
    } else {
        accounts = new ArrayList<>(accountUuids.length);
        for (int i = 0, len = accountUuids.length; i < len; i++) {
            String accountUuid = accountUuids[i];
            accounts.set(i, preferences.getAccount(accountUuid));
        }
    }
    ContentResolver cr = context.getContentResolver();
    int unreadMessageCount = 0;
    int flaggedMessageCount = 0;
    String[] projection = { StatsColumns.UNREAD_COUNT, StatsColumns.FLAGGED_COUNT };
    for (Account account : accounts) {
        StringBuilder query = new StringBuilder();
        List<String> queryArgs = new ArrayList<>();
        ConditionsTreeNode conditions = search.getConditions();
        SqlQueryBuilder.buildWhereClause(account, conditions, query, queryArgs);
        String selection = query.toString();
        String[] selectionArgs = queryArgs.toArray(new String[queryArgs.size()]);
        Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/stats");
        // Query content provider to get the account stats
        Cursor cursor = cr.query(uri, projection, selection, selectionArgs, null);
        try {
            if (cursor != null && cursor.moveToFirst()) {
                unreadMessageCount += cursor.getInt(0);
                flaggedMessageCount += cursor.getInt(1);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
    // Create AccountStats instance...
    AccountStats stats = new AccountStats();
    stats.unreadMessageCount = unreadMessageCount;
    stats.flaggedMessageCount = flaggedMessageCount;
    // ...and notify the listener
    if (listener != null) {
        listener.accountStatusChanged(searchAccount, stats);
    }
    return stats;
}
Also used : ConditionsTreeNode(com.fsck.k9.search.ConditionsTreeNode) SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) ContentResolver(android.content.ContentResolver) LocalSearch(com.fsck.k9.search.LocalSearch) Preferences(com.fsck.k9.Preferences) AccountStats(com.fsck.k9.AccountStats)

Aggregations

LocalSearch (com.fsck.k9.search.LocalSearch)13 Account (com.fsck.k9.Account)6 SearchAccount (com.fsck.k9.search.SearchAccount)6 SearchCondition (com.fsck.k9.search.SearchSpecification.SearchCondition)4 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 Uri (android.net.Uri)3 AccountStats (com.fsck.k9.AccountStats)3 BaseAccount (com.fsck.k9.BaseAccount)3 ArrayList (java.util.ArrayList)3 ContentResolver (android.content.ContentResolver)2 Cursor (android.database.Cursor)2 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)2 Preferences (com.fsck.k9.Preferences)2 MessageListFragment (com.fsck.k9.fragment.MessageListFragment)2 LocalStore (com.fsck.k9.mailstore.LocalStore)2 ConditionsTreeNode (com.fsck.k9.search.ConditionsTreeNode)2 SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1