diff --git a/src/com/android/email/Utility.java b/src/com/android/email/Utility.java index 000eeb874..40b781286 100644 --- a/src/com/android/email/Utility.java +++ b/src/com/android/email/Utility.java @@ -90,12 +90,6 @@ public class Utility { private static final Pattern DATE_CLEANUP_PATTERN_WRONG_TIMEZONE = Pattern.compile("GMT([-+]\\d{4})$"); - private static final String SELECTION_FLAG_LOADED_FOR_VISIBLE_MESSAGE = - " AND (" - + MessageColumns.FLAG_LOADED + " IN (" - + Message.FLAG_LOADED_PARTIAL + "," + Message.FLAG_LOADED_COMPLETE - + "))"; - public final static String readInputStream(InputStream in, String encoding) throws IOException { InputStreamReader reader = new InputStreamReader(in, encoding); StringBuffer sb = new StringBuffer(); @@ -302,6 +296,9 @@ public class Utility { /** * Returns the where clause for a message list selection. * + * TODO This method needs to be rewritten to use the _SELECTION constants defined in + * EmailContent.Message. + * * MUST NOT be called on the UI thread. */ public static String buildMailboxIdSelection(Context context, long mailboxId) { @@ -355,7 +352,7 @@ public class Utility { // This makes sure they're not visible in the message list. // This means unread counts on the mailbox list can be different from the // number of messages in the message list, but it should be transient... - selection.append(SELECTION_FLAG_LOADED_FOR_VISIBLE_MESSAGE); + selection.append(" AND ").append(Message.FLAG_LOADED_SELECTION); } return selection.toString(); diff --git a/src/com/android/email/provider/EmailContent.java b/src/com/android/email/provider/EmailContent.java index f9b633622..4e3db6608 100644 --- a/src/com/android/email/provider/EmailContent.java +++ b/src/com/android/email/provider/EmailContent.java @@ -544,18 +544,26 @@ public abstract class EmailContent { private static final String ACCOUNT_KEY_SELECTION = MessageColumns.ACCOUNT_KEY + "=?"; + /** Selection for messages that are loaded */ + public static final String FLAG_LOADED_SELECTION = + MessageColumns.FLAG_LOADED + " IN (" + + Message.FLAG_LOADED_PARTIAL + "," + Message.FLAG_LOADED_COMPLETE + + ")"; + public static final String ALL_FAVORITE_SELECTION = MessageColumns.FLAG_FAVORITE + "=1 AND " + MessageColumns.MAILBOX_KEY + " NOT IN (" + "SELECT " + MailboxColumns.ID + " FROM " + Mailbox.TABLE_NAME + "" + " WHERE " + MailboxColumns.TYPE + " = " + Mailbox.TYPE_TRASH - + ")"; + + ")" + + " AND " + FLAG_LOADED_SELECTION; /** Selection to retrieve all messages in "inbox" for any account */ public static final String INBOX_SELECTION = MessageColumns.MAILBOX_KEY + " IN (" + "SELECT " + MailboxColumns.ID + " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + " = " + Mailbox.TYPE_INBOX - + ")"; + + ")" + + " AND " + FLAG_LOADED_SELECTION; /** Selection to retrieve unread messages in "inbox" for any account */ public static final String UNREAD_SELECTION = MessageColumns.FLAG_READ + "=0 AND " + INBOX_SELECTION; diff --git a/tests/src/com/android/email/provider/ProviderTests.java b/tests/src/com/android/email/provider/ProviderTests.java index df3bf155b..756c2fa1a 100644 --- a/tests/src/com/android/email/provider/ProviderTests.java +++ b/tests/src/com/android/email/provider/ProviderTests.java @@ -1964,23 +1964,23 @@ public class ProviderTests extends ProviderTestCase2 { // Create some messages // b1 (account 1, inbox): 1 message, including 1 starred - Message m11 = createMessage(c, b1, true, false); + Message m11 = createMessage(c, b1, true, false, Message.FLAG_LOADED_COMPLETE); // b2 (account 1, outbox): 2 message, including 1 starred - Message m21 = createMessage(c, b2, false, false); - Message m22 = createMessage(c, b2, true, true); + Message m21 = createMessage(c, b2, false, false, Message.FLAG_LOADED_COMPLETE); + Message m22 = createMessage(c, b2, true, true, Message.FLAG_LOADED_COMPLETE); // 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); + Message m31 = createMessage(c, b3, false, false, Message.FLAG_LOADED_COMPLETE); + Message m32 = createMessage(c, b3, false, false, Message.FLAG_LOADED_COMPLETE); + Message m33 = createMessage(c, b3, true, true, Message.FLAG_LOADED_COMPLETE); // b4 (account 2, outbox) has no messages. // bt (account 2, trash) has 3 messages, including 2 starred - Message mt1 = createMessage(c, bt, true, false); - Message mt2 = createMessage(c, bt, true, false); - Message mt3 = createMessage(c, bt, false, false); + Message mt1 = createMessage(c, bt, true, false, Message.FLAG_LOADED_COMPLETE); + Message mt2 = createMessage(c, bt, true, false, Message.FLAG_LOADED_COMPLETE); + Message mt3 = createMessage(c, bt, false, false, Message.FLAG_LOADED_COMPLETE); // Check message counts assertEquals(1, getMessageCount(b1.mId)); @@ -2072,8 +2072,17 @@ public class ProviderTests extends ProviderTestCase2 { } private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read) { - return ProviderTestUtils.setupMessage("1", b.mAccountKey, b.mId, true, true, c, starred, - read); + return ProviderTestUtils.setupMessage( + "1", b.mAccountKey, b.mId, true, true, c, starred, read); + } + + private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read, + int flagLoaded) { + Message message = ProviderTestUtils.setupMessage( + "1", b.mAccountKey, b.mId, true, false, c, starred, read); + message.mFlagLoaded = flagLoaded; + message.save(c); + return message; } public void testAccountIsEasAccount() { diff --git a/tests/src/com/android/email/provider/WidgetProviderTests.java b/tests/src/com/android/email/provider/WidgetProviderTests.java index b4f9da825..97cf267cc 100644 --- a/tests/src/com/android/email/provider/WidgetProviderTests.java +++ b/tests/src/com/android/email/provider/WidgetProviderTests.java @@ -80,9 +80,13 @@ public class WidgetProviderTests extends ProviderTestCase2 { return messageCount; } - private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read) { - return ProviderTestUtils.setupMessage("1", b.mAccountKey, b.mId, true, true, c, starred, - read); + private static Message createMessage(Context c, Mailbox b, boolean starred, boolean read, + int flagLoaded) { + Message message = ProviderTestUtils.setupMessage( + "1", b.mAccountKey, b.mId, true, false, c, starred, read); + message.mFlagLoaded = flagLoaded; + message.save(c); + return message; } public void testWidgetSwitcher() { @@ -136,24 +140,26 @@ public class WidgetProviderTests extends ProviderTestCase2 { "boxT", a2.mId, true, mMockContext, Mailbox.TYPE_TRASH); // Create some messages - // b1 (account 1, inbox): 1 message, including 1 starred - Message m11 = createMessage(mMockContext, b1, true, false); + // b1 (account 1, inbox): 2 messages, including 1 starred, 1 unloaded + Message m11 = createMessage(mMockContext, b1, true, false, Message.FLAG_LOADED_COMPLETE); + Message m12 = createMessage(mMockContext, b1, false, false, Message.FLAG_LOADED_UNLOADED); - // b2 (account 1, outbox): 2 message, including 1 starred - Message m21 = createMessage(mMockContext, b2, false, false); - Message m22 = createMessage(mMockContext, b2, true, true); + // b2 (account 1, outbox): 2 messages, including 1 starred + Message m21 = createMessage(mMockContext, b2, false, false, Message.FLAG_LOADED_COMPLETE); + Message m22 = createMessage(mMockContext, b2, true, true, Message.FLAG_LOADED_COMPLETE); - // b3 (account 2, inbox): 3 message, including 1 starred - Message m31 = createMessage(mMockContext, b3, false, false); - Message m32 = createMessage(mMockContext, b3, false, true); - Message m33 = createMessage(mMockContext, b3, true, true); + // b3 (account 2, inbox): 4 messages, including 1 starred, 1 unloaded + Message m31 = createMessage(mMockContext, b3, false, false, Message.FLAG_LOADED_COMPLETE); + Message m32 = createMessage(mMockContext, b3, false, true, Message.FLAG_LOADED_COMPLETE); + Message m33 = createMessage(mMockContext, b3, true, true, Message.FLAG_LOADED_COMPLETE); + Message m34 = createMessage(mMockContext, b3, true, true, Message.FLAG_LOADED_UNLOADED); // b4 (account 2, outbox) has no messages. - // bt (account 2, trash) has 3 messages, including 2 starred - Message mt1 = createMessage(mMockContext, bt, true, false); - Message mt2 = createMessage(mMockContext, bt, true, true); - Message mt3 = createMessage(mMockContext, bt, false, false); + // bt (account 2, trash): 3 messages, including 2 starred + Message mt1 = createMessage(mMockContext, bt, true, false, Message.FLAG_LOADED_COMPLETE); + Message mt2 = createMessage(mMockContext, bt, true, true, Message.FLAG_LOADED_COMPLETE); + Message mt3 = createMessage(mMockContext, bt, false, false, Message.FLAG_LOADED_COMPLETE); assertEquals(4, getMessageCount(ViewType.ALL_INBOX)); assertEquals(3, getMessageCount(ViewType.STARRED));