From 9c0da8b84f2e52b38134719fcbf80c9d3c777970 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 11 Jan 2011 16:43:06 -0800 Subject: [PATCH] Don't show starred mailbox, if account has no starred Bug 3334963 Change-Id: I751e56731b990a6e94b8547a577a84c1a848cbc7 --- src/com/android/email/activity/MailboxesAdapter.java | 6 ++++-- src/com/android/email/provider/EmailContent.java | 11 +++++++++++ .../src/com/android/email/provider/ProviderTests.java | 11 ++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/com/android/email/activity/MailboxesAdapter.java b/src/com/android/email/activity/MailboxesAdapter.java index 19c4cb6f3..e71239dec 100644 --- a/src/com/android/email/activity/MailboxesAdapter.java +++ b/src/com/android/email/activity/MailboxesAdapter.java @@ -350,6 +350,7 @@ import android.widget.TextView; private static class MailboxesLoader extends ThrottlingCursorLoader { private final Context mContext; private final int mMode; + private final long mAccountId; private static String getSelection(int mode) { if (mode == MODE_MOVE_TO_TARGET) { @@ -365,6 +366,7 @@ import android.widget.TextView; new String[] { String.valueOf(accountId) }, MAILBOX_ORDER_BY); mContext = context; mMode = mode; + mAccountId = accountId; } @Override @@ -381,10 +383,10 @@ import android.widget.TextView; return Utility.CloseTraceCursorWrapper.get(mailboxesCursor); } - // Add "Starred". + // Add "Starred", only if the account has at least one starred message. // TODO It's currently "combined starred", but the plan is to make it per-account // starred. - final int starredCount = Message.getFavoriteMessageCount(mContext); + final int starredCount = Message.getFavoriteMessageCount(mContext, mAccountId); if (starredCount == 0) { return Utility.CloseTraceCursorWrapper.get(mailboxesCursor); // no starred message } diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index b102f2bf6..91952f782 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -544,6 +544,9 @@ public abstract class EmailContent { private static final String FAVORITE_COUNT_SELECTION = MessageColumns.FLAG_FAVORITE + "= 1"; + private static final String ACCOUNT_FAVORITE_COUNT_SELECTION = + MessageColumns.FLAG_FAVORITE + "= 1 AND " + MessageColumns.ACCOUNT_KEY + "=?"; + private static final String ACCOUNT_KEY_SELECTION = MessageColumns.ACCOUNT_KEY + "=?"; @@ -858,6 +861,14 @@ public abstract class EmailContent { return count(context, Message.CONTENT_URI, FAVORITE_COUNT_SELECTION, null); } + /** + * @return number of favorite (starred) messages for an account + */ + public static int getFavoriteMessageCount(Context context, long accountId) { + return count(context, Message.CONTENT_URI, ACCOUNT_FAVORITE_COUNT_SELECTION, + new String[]{Long.toString(accountId)}); + } + public static long getKeyColumnLong(Context context, long messageId, String column) { String[] columns = Utility.getRowColumns(context, Message.CONTENT_URI, messageId, column); diff --git a/tests/src/com/android/email/provider/ProviderTests.java b/tests/src/com/android/email/provider/ProviderTests.java index 7564ccdaf..f1f6c596f 100644 --- a/tests/src/com/android/email/provider/ProviderTests.java +++ b/tests/src/com/android/email/provider/ProviderTests.java @@ -1914,6 +1914,7 @@ public class ProviderTests extends ProviderTestCase2 { * - {@link Mailbox#getUnreadCountByAccountAndMailboxType(Context, long, int)} * - {@link Mailbox#getUnreadCountByMailboxType(Context, int)} * - {@link Message#getFavoriteMessageCount(Context)} + * - {@link Message#getFavoriteMessageCount(Context, long)} */ public void testMessageCount() { final Context c = mMockContext; @@ -1936,6 +1937,8 @@ public class ProviderTests extends ProviderTestCase2 { assertEquals(0, getMessageCount(b4.mId)); assertEquals(0, Message.getFavoriteMessageCount(c)); + assertEquals(0, Message.getFavoriteMessageCount(c, a1.mId)); + assertEquals(0, Message.getFavoriteMessageCount(c, a2.mId)); assertEquals(0, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_INBOX)); assertEquals(0, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_OUTBOX)); assertEquals(0, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_INBOX)); @@ -1953,14 +1956,14 @@ public class ProviderTests extends ProviderTestCase2 { // 1. Test for insert triggers. // Create some messages - // b1 (account 1, inbox): 1 message + // b1 (account 1, inbox): 1 message, including 1 starred Message m11 = createMessage(c, b1, true, false); - // b2 (account 1, outbox): 2 message + // b2 (account 1, outbox): 2 message, including 1 starred Message m21 = createMessage(c, b2, false, false); Message m22 = createMessage(c, b2, true, true); - // b3 (account 2, inbox): 3 message + // b3 (account 2, inbox): 3 message, including 1 starred Message m31 = createMessage(c, b3, false, false); Message m32 = createMessage(c, b3, false, false); Message m33 = createMessage(c, b3, true, true); @@ -1975,6 +1978,8 @@ public class ProviderTests extends ProviderTestCase2 { // Check the simple counting methods. assertEquals(3, Message.getFavoriteMessageCount(c)); + assertEquals(2, Message.getFavoriteMessageCount(c, a1.mId)); + assertEquals(1, Message.getFavoriteMessageCount(c, a2.mId)); assertEquals(3, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_INBOX)); assertEquals(1, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_OUTBOX)); assertEquals(4, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_INBOX));