diff --git a/src/com/android/email/FolderProperties.java b/src/com/android/email/FolderProperties.java index 4b927dcc0..c5823c79b 100644 --- a/src/com/android/email/FolderProperties.java +++ b/src/com/android/email/FolderProperties.java @@ -16,14 +16,16 @@ package com.android.email; +import com.android.emailcommon.provider.EmailContent.MailboxColumns; +import com.android.emailcommon.provider.EmailContent.Message; +import com.android.emailcommon.provider.Mailbox; +import com.google.common.base.Preconditions; + import android.content.Context; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.drawable.Drawable; -import com.android.emailcommon.provider.EmailContent.MailboxColumns; -import com.android.emailcommon.provider.Mailbox; - // TODO When the UI is settled, cache all strings/drawables /** @@ -174,6 +176,24 @@ public class FolderProperties { ); } + public int getMessageCountForCombinedMailbox(long mailboxId) { + Preconditions.checkState(mailboxId < -1L); + if ((mailboxId == Mailbox.QUERY_ALL_INBOXES) + || (mailboxId == Mailbox.QUERY_ALL_UNREAD)) { + return Mailbox.getUnreadCountByMailboxType(mContext, Mailbox.TYPE_INBOX); + + } else if (mailboxId == Mailbox.QUERY_ALL_FAVORITES) { + return Message.getFavoriteMessageCount(mContext); + + } else if (mailboxId == Mailbox.QUERY_ALL_DRAFTS) { + return Mailbox.getMessageCountByMailboxType(mContext, Mailbox.TYPE_DRAFTS); + + } else if (mailboxId == Mailbox.QUERY_ALL_OUTBOX) { + return Mailbox.getMessageCountByMailboxType(mContext, Mailbox.TYPE_OUTBOX); + } + throw new IllegalStateException("Invalid mailbox ID"); + } + /** * Lookup icons of special mailboxes */ diff --git a/src/com/android/email/activity/AccountSelectorAdapter.java b/src/com/android/email/activity/AccountSelectorAdapter.java index 4000c4739..047a3fb53 100644 --- a/src/com/android/email/activity/AccountSelectorAdapter.java +++ b/src/com/android/email/activity/AccountSelectorAdapter.java @@ -17,6 +17,7 @@ package com.android.email.activity; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; import com.android.email.FolderProperties; import com.android.email.R; @@ -495,11 +496,7 @@ public class AccountSelectorAdapter extends CursorAdapter { // We need to treat ACCOUNT_ID_COMBINED_VIEW specially... mAccountExists = true; mAccountDisplayName = getCombinedViewDisplayName(context); - mMailboxDisplayName = FolderProperties.getInstance(context) - .getCombinedMailboxName(mMailboxId); - - // TODO Would be nicer to show message count for combined mailboxes too.. - mMailboxMessageCount = 0; + setCombinedMailboxInfo(context, mailboxId); return; } @@ -517,6 +514,13 @@ public class AccountSelectorAdapter extends CursorAdapter { if (mMailboxId == Mailbox.NO_MAILBOX) { return; } + // Combined mailbox? + // Unfortunately this can happen even when account != ACCOUNT_ID_COMBINED_VIEW, + // when you open "starred" on 2-pane on non-combined view. + if (mMailboxId < 0) { + setCombinedMailboxInfo(context, mailboxId); + return; + } // Get mailbox info final ContentResolver r = context.getContentResolver(); @@ -534,6 +538,15 @@ public class AccountSelectorAdapter extends CursorAdapter { } } + private void setCombinedMailboxInfo(Context context, long mailboxId) { + Preconditions.checkState(mailboxId < -1, "Not combined mailbox"); + mMailboxDisplayName = FolderProperties.getInstance(context) + .getCombinedMailboxName(mMailboxId); + + mMailboxMessageCount = FolderProperties.getInstance(context) + .getMessageCountForCombinedMailbox(mailboxId); + } + /** * Returns the cursor position of the item with the given ID. Or {@link #UNKNOWN_POSITION} * if the given ID does not exist. diff --git a/src/com/android/email/activity/MailboxFragmentAdapter.java b/src/com/android/email/activity/MailboxFragmentAdapter.java index 2762caf2b..c0353644e 100644 --- a/src/com/android/email/activity/MailboxFragmentAdapter.java +++ b/src/com/android/email/activity/MailboxFragmentAdapter.java @@ -467,11 +467,12 @@ class MailboxFragmentAdapter extends CursorAdapter { row.add(accountId); } - private static void addCombinedMailboxRow(MatrixCursor cursor, long id, int mailboxType, - int count, boolean showAlways) { + private static void addCombinedMailboxRow(Context context, MatrixCursor cursor, long id, + int mailboxType, boolean showAlways) { if (id >= 0) { throw new IllegalArgumentException(); // Must be QUERY_ALL_*, which are all negative } + int count = FolderProperties.getInstance(context).getMessageCountForCombinedMailbox(id); if (showAlways || (count > 0)) { addMailboxRow( cursor, id, "", mailboxType, count, count, ROW_TYPE_MAILBOX, Mailbox.FLAG_NONE, @@ -563,9 +564,8 @@ class MailboxFragmentAdapter extends CursorAdapter { int accountStarredCount = Message.getFavoriteMessageCount(mContext, mAccountId); if (accountStarredCount > 0) { // Only add "Starred", if there is at least one starred message - final int totalStarredCount = Message.getFavoriteMessageCount(mContext); - addCombinedMailboxRow(starredCursor, Mailbox.QUERY_ALL_FAVORITES, - Mailbox.TYPE_MAIL, totalStarredCount, true); + addCombinedMailboxRow(mContext, starredCursor, Mailbox.QUERY_ALL_FAVORITES, + Mailbox.TYPE_MAIL, true); } returnCursor = new MergeCursor(new Cursor[] { starredCursor, systemMailboxCursor, recentCursor, headerCursor, @@ -615,23 +615,19 @@ class MailboxFragmentAdapter extends CursorAdapter { } @VisibleForTesting - static MatrixCursor buildCombinedMailboxes(Context context, Cursor innerCursor) { + static MatrixCursor buildCombinedMailboxes(Context c, Cursor innerCursor) { MatrixCursor cursor = new ClosingMatrixCursor(MATRIX_PROJECTION, innerCursor); // Combined inbox -- show unread count - addCombinedMailboxRow(cursor, Mailbox.QUERY_ALL_INBOXES, Mailbox.TYPE_INBOX, - Mailbox.getUnreadCountByMailboxType(context, Mailbox.TYPE_INBOX), true); + addCombinedMailboxRow(c, cursor, Mailbox.QUERY_ALL_INBOXES, Mailbox.TYPE_INBOX, true); // Favorite (starred) -- show # of favorites - addCombinedMailboxRow(cursor, Mailbox.QUERY_ALL_FAVORITES, Mailbox.TYPE_MAIL, - Message.getFavoriteMessageCount(context), false); + addCombinedMailboxRow(c, cursor, Mailbox.QUERY_ALL_FAVORITES, Mailbox.TYPE_MAIL, false); // Drafts -- show # of drafts - addCombinedMailboxRow(cursor, Mailbox.QUERY_ALL_DRAFTS, Mailbox.TYPE_DRAFTS, - Mailbox.getMessageCountByMailboxType(context, Mailbox.TYPE_DRAFTS), false); + addCombinedMailboxRow(c, cursor, Mailbox.QUERY_ALL_DRAFTS, Mailbox.TYPE_DRAFTS, false); // Outbox -- # of outstanding messages - addCombinedMailboxRow(cursor, Mailbox.QUERY_ALL_OUTBOX, Mailbox.TYPE_OUTBOX, - Mailbox.getMessageCountByMailboxType(context, Mailbox.TYPE_OUTBOX), false); + addCombinedMailboxRow(c, cursor, Mailbox.QUERY_ALL_OUTBOX, Mailbox.TYPE_OUTBOX, false); return cursor; }