Search in sources :

Example 1 with SearchAccount

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

the class UnreadWidgetProvider method updateWidget.

public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, String accountUuid) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.unread_widget_layout);
    int unreadCount = 0;
    String accountName = context.getString(R.string.app_name);
    Intent clickIntent = null;
    try {
        BaseAccount account = null;
        AccountStats stats = null;
        SearchAccount searchAccount = null;
        if (SearchAccount.UNIFIED_INBOX.equals(accountUuid)) {
            searchAccount = SearchAccount.createUnifiedInboxAccount(context);
        } else if (SearchAccount.ALL_MESSAGES.equals(accountUuid)) {
            searchAccount = SearchAccount.createAllMessagesAccount(context);
        }
        if (searchAccount != null) {
            account = searchAccount;
            MessagingController controller = MessagingController.getInstance(context);
            stats = controller.getSearchAccountStatsSynchronous(searchAccount, null);
            clickIntent = MessageList.intentDisplaySearch(context, searchAccount.getRelatedSearch(), false, true, true);
        } else {
            Account realAccount = Preferences.getPreferences(context).getAccount(accountUuid);
            if (realAccount != null) {
                account = realAccount;
                stats = realAccount.getStats(context);
                if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
                    clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, false);
                } else {
                    LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
                    search.addAllowedFolder(realAccount.getAutoExpandFolderName());
                    search.addAccountUuid(account.getUuid());
                    clickIntent = MessageList.intentDisplaySearch(context, search, false, true, true);
                }
                clickIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            }
        }
        if (account != null) {
            accountName = account.getDescription();
        }
        if (stats != null) {
            unreadCount = stats.unreadMessageCount;
        }
    } catch (Exception e) {
        Timber.e(e, "Error getting widget configuration");
    }
    if (unreadCount <= 0) {
        // Hide TextView for unread count if there are no unread messages.
        remoteViews.setViewVisibility(R.id.unread_count, View.GONE);
    } else {
        remoteViews.setViewVisibility(R.id.unread_count, View.VISIBLE);
        String displayCount = (unreadCount <= MAX_COUNT) ? String.valueOf(unreadCount) : String.valueOf(MAX_COUNT) + "+";
        remoteViews.setTextViewText(R.id.unread_count, displayCount);
    }
    remoteViews.setTextViewText(R.id.account_name, accountName);
    if (clickIntent == null) {
        // If the widget configuration couldn't be loaded we open the configuration
        // activity when the user clicks the widget.
        clickIntent = new Intent(context, UnreadWidgetConfiguration.class);
        clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    }
    clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.unread_widget_layout, pendingIntent);
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) UnreadWidgetConfiguration(com.fsck.k9.activity.UnreadWidgetConfiguration) MessagingController(com.fsck.k9.controller.MessagingController) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SearchAccount(com.fsck.k9.search.SearchAccount) RemoteViews(android.widget.RemoteViews) LocalSearch(com.fsck.k9.search.LocalSearch) BaseAccount(com.fsck.k9.BaseAccount) PendingIntent(android.app.PendingIntent) AccountStats(com.fsck.k9.AccountStats)

Example 2 with SearchAccount

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

the class Accounts method createUnreadSearch.

public static LocalSearch createUnreadSearch(Context context, BaseAccount account) {
    String searchTitle = context.getString(R.string.search_title, account.getDescription(), context.getString(R.string.unread_modifier));
    LocalSearch search;
    if (account instanceof SearchAccount) {
        search = ((SearchAccount) account).getRelatedSearch().clone();
        search.setName(searchTitle);
    } else {
        search = new LocalSearch(searchTitle);
        search.addAccountUuid(account.getUuid());
        Account realAccount = (Account) account;
        realAccount.excludeSpecialFolders(search);
        realAccount.limitToDisplayableFolders(search);
    }
    search.and(SearchField.READ, "1", Attribute.NOT_EQUALS);
    return search;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) BaseAccount(com.fsck.k9.BaseAccount) LocalSearch(com.fsck.k9.search.LocalSearch) SearchAccount(com.fsck.k9.search.SearchAccount)

Example 3 with SearchAccount

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

the class MessageListWidgetProvider method viewUnifiedInboxPendingIntent.

private PendingIntent viewUnifiedInboxPendingIntent(Context context) {
    SearchAccount unifiedInboxAccount = SearchAccount.createUnifiedInboxAccount();
    Intent intent = MessageList.intentDisplaySearch(context, unifiedInboxAccount.getRelatedSearch(), true, true, true);
    return PendingIntent.getActivity(context, -1, intent, FLAG_UPDATE_CURRENT | FLAG_IMMUTABLE);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SearchAccount(com.fsck.k9.search.SearchAccount)

Example 4 with SearchAccount

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

the class MessageListFragment method isRemoteSearchAllowed.

public boolean isRemoteSearchAllowed() {
    if (!search.isManualSearch() || remoteSearchPerformed || !singleFolderMode) {
        return false;
    }
    boolean allowRemoteSearch = false;
    final Account searchAccount = account;
    if (searchAccount != null) {
        allowRemoteSearch = searchAccount.allowRemoteSearch();
    }
    return allowRemoteSearch;
}
Also used : Account(com.fsck.k9.Account)

Example 5 with SearchAccount

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

the class MessageListFragment method onStop.

/**
     * We need to do some special clean up when leaving a remote search result screen. If no
     * remote search is in progress, this method does nothing special.
     */
@Override
public void onStop() {
    // If we represent a remote search, then kill that before going back.
    if (isRemoteSearch() && remoteSearchFuture != null) {
        try {
            Timber.i("Remote search in progress, attempting to abort...");
            // Canceling the future stops any message fetches in progress.
            // mayInterruptIfRunning = true
            final boolean cancelSuccess = remoteSearchFuture.cancel(true);
            if (!cancelSuccess) {
                Timber.e("Could not cancel remote search future.");
            }
            // Closing the folder will kill off the connection if we're mid-search.
            final Account searchAccount = account;
            final Folder remoteFolder = currentFolder.folder;
            remoteFolder.close();
            // Send a remoteSearchFinished() message for good measure.
            activityListener.remoteSearchFinished(currentFolder.name, 0, searchAccount.getRemoteSearchNumResults(), null);
        } catch (Exception e) {
            // Since the user is going back, log and squash any exceptions.
            Timber.e(e, "Could not abort remote search before going back");
        }
    }
    super.onStop();
}
Also used : Account(com.fsck.k9.Account) Folder(com.fsck.k9.mail.Folder) ChooseFolder(com.fsck.k9.activity.ChooseFolder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) MessagingException(com.fsck.k9.mail.MessagingException)

Aggregations

Account (com.fsck.k9.Account)9 SearchAccount (com.fsck.k9.search.SearchAccount)8 BaseAccount (com.fsck.k9.BaseAccount)6 LocalSearch (com.fsck.k9.search.LocalSearch)4 Intent (android.content.Intent)3 PendingIntent (android.app.PendingIntent)2 AccountStats (com.fsck.k9.AccountStats)2 MessagingController (com.fsck.k9.controller.MessagingController)2 SuppressLint (android.annotation.SuppressLint)1 ContentResolver (android.content.ContentResolver)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 Parcelable (android.os.Parcelable)1 MenuItem (android.view.MenuItem)1 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)1 RemoteViews (android.widget.RemoteViews)1 Toast (android.widget.Toast)1 Preferences (com.fsck.k9.Preferences)1 ChooseFolder (com.fsck.k9.activity.ChooseFolder)1 UnreadWidgetConfiguration (com.fsck.k9.activity.UnreadWidgetConfiguration)1