Don't show trashed messages in Starred mailbox
Also show the *total* starred message count (excluding trashed starred) in the mailbox list, not *per-account* starred count. Bug 3346872 Bug 2149412 Change-Id: I2274f215f994b62280ac6138982b927cec22c677
This commit is contained in:
parent
1ec737ce28
commit
d072f9905d
@ -341,7 +341,7 @@ public class Utility {
|
||||
} else if (mailboxId == Mailbox.QUERY_ALL_UNREAD) {
|
||||
selection.append(Message.FLAG_READ + "=0");
|
||||
} else if (mailboxId == Mailbox.QUERY_ALL_FAVORITES) {
|
||||
selection.append(Message.FLAG_FAVORITE + "=1");
|
||||
selection.append(Message.ALL_FAVORITE_SELECTION);
|
||||
} else {
|
||||
selection.append(MessageColumns.MAILBOX_KEY + "=" + mailboxId);
|
||||
if (Mailbox.getMailboxType(context, mailboxId) == Mailbox.TYPE_OUTBOX) {
|
||||
|
@ -386,15 +386,16 @@ import android.widget.TextView;
|
||||
// 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, mAccountId);
|
||||
if (starredCount == 0) {
|
||||
final int accountStarredCount = Message.getFavoriteMessageCount(mContext, mAccountId);
|
||||
if (accountStarredCount == 0) {
|
||||
return Utility.CloseTraceCursorWrapper.get(mailboxesCursor); // no starred message
|
||||
}
|
||||
|
||||
final MatrixCursor starredCursor = new MatrixCursor(getProjection());
|
||||
|
||||
final int totalStarredCount = Message.getFavoriteMessageCount(mContext);
|
||||
addSummaryMailboxRow(mContext, starredCursor,
|
||||
Mailbox.QUERY_ALL_FAVORITES, Mailbox.TYPE_MAIL, starredCount, true);
|
||||
Mailbox.QUERY_ALL_FAVORITES, Mailbox.TYPE_MAIL, totalStarredCount, true);
|
||||
|
||||
return Utility.CloseTraceCursorWrapper.get(
|
||||
new MergeCursor(new Cursor[] {starredCursor, mailboxesCursor}));
|
||||
|
@ -541,15 +541,19 @@ public abstract class EmailContent {
|
||||
|
||||
public static final String[] ID_COLUMN_PROJECTION = new String[] { RECORD_ID };
|
||||
|
||||
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 + "=?";
|
||||
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
|
||||
+ ")";
|
||||
|
||||
private static final String ACCOUNT_KEY_SELECTION =
|
||||
MessageColumns.ACCOUNT_KEY + "=?";
|
||||
|
||||
private static final String ACCOUNT_FAVORITE_SELECTION =
|
||||
ACCOUNT_KEY_SELECTION + " AND " + ALL_FAVORITE_SELECTION;
|
||||
|
||||
/**
|
||||
* Selection for latest incoming messages. In order to tell whether incoming or not,
|
||||
* we need the mailbox type, which is in the mailbox table, not the message table, so
|
||||
@ -858,14 +862,14 @@ public abstract class EmailContent {
|
||||
* @return number of favorite (starred) messages throughout all accounts.
|
||||
*/
|
||||
public static int getFavoriteMessageCount(Context context) {
|
||||
return count(context, Message.CONTENT_URI, FAVORITE_COUNT_SELECTION, null);
|
||||
return count(context, Message.CONTENT_URI, ALL_FAVORITE_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,
|
||||
return count(context, Message.CONTENT_URI, ACCOUNT_FAVORITE_SELECTION,
|
||||
new String[]{Long.toString(accountId)});
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ public class WidgetProvider extends AppWidgetProvider {
|
||||
public enum ViewType {
|
||||
ALL_MAIL(null, NO_ARGUMENTS, R.string.widget_all_mail),
|
||||
UNREAD(MessageColumns.FLAG_READ + "=0", NO_ARGUMENTS, R.string.widget_unread),
|
||||
STARRED(MessageColumns.FLAG_FAVORITE + "=1", NO_ARGUMENTS, R.string.widget_starred),
|
||||
STARRED(Message.ALL_FAVORITE_SELECTION, NO_ARGUMENTS, R.string.widget_starred),
|
||||
ACCOUNT(MessageColumns.ACCOUNT_KEY + "=?", new String[1], 0);
|
||||
|
||||
private final String selection;
|
||||
|
@ -55,6 +55,8 @@ public class MailboxesAdapterTest extends ProviderTestCase2<EmailProvider> {
|
||||
Mailbox b2o = ProviderTestUtils.setupMailbox("box2i", a2.mId, true, c, Mailbox.TYPE_OUTBOX);
|
||||
Mailbox b1d = ProviderTestUtils.setupMailbox("box1d", a1.mId, true, c, Mailbox.TYPE_DRAFTS);
|
||||
Mailbox b2d = ProviderTestUtils.setupMailbox("box2d", a2.mId, true, c, Mailbox.TYPE_DRAFTS);
|
||||
Mailbox b1t = ProviderTestUtils.setupMailbox("box1t", a1.mId, true, c, Mailbox.TYPE_TRASH);
|
||||
Mailbox b2t = ProviderTestUtils.setupMailbox("box2t", a2.mId, true, c, Mailbox.TYPE_TRASH);
|
||||
|
||||
createMessage(c, b1i, false, false);
|
||||
createMessage(c, b2i, true, true);
|
||||
@ -68,6 +70,8 @@ public class MailboxesAdapterTest extends ProviderTestCase2<EmailProvider> {
|
||||
createMessage(c, b2d, false, true);
|
||||
createMessage(c, b2d, false, true);
|
||||
|
||||
createMessage(c, b2t, true, true); // Starred message in trash; All Starred excludes it.
|
||||
|
||||
// Kick the method
|
||||
Cursor cursor = MailboxesAdapter.getSpecialMailboxesCursor(c);
|
||||
|
||||
|
@ -1928,6 +1928,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
Mailbox b2 = ProviderTestUtils.setupMailbox("box2", a1.mId, true, c, Mailbox.TYPE_OUTBOX);
|
||||
Mailbox b3 = ProviderTestUtils.setupMailbox("box3", a2.mId, true, c, Mailbox.TYPE_INBOX);
|
||||
Mailbox b4 = ProviderTestUtils.setupMailbox("box4", a2.mId, true, c, Mailbox.TYPE_OUTBOX);
|
||||
Mailbox bt = ProviderTestUtils.setupMailbox("boxT", a2.mId, true, c, Mailbox.TYPE_TRASH);
|
||||
|
||||
// 0. Check the initial values, just in case.
|
||||
|
||||
@ -1935,6 +1936,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
assertEquals(0, getMessageCount(b2.mId));
|
||||
assertEquals(0, getMessageCount(b3.mId));
|
||||
assertEquals(0, getMessageCount(b4.mId));
|
||||
assertEquals(0, getMessageCount(bt.mId));
|
||||
|
||||
assertEquals(0, Message.getFavoriteMessageCount(c));
|
||||
assertEquals(0, Message.getFavoriteMessageCount(c, a1.mId));
|
||||
@ -1943,15 +1945,20 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
assertEquals(0, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(0, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_INBOX));
|
||||
assertEquals(0, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(0, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_TRASH));
|
||||
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_INBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_TRASH));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_INBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_TRASH));
|
||||
|
||||
// 1. Test for insert triggers.
|
||||
|
||||
@ -1970,29 +1977,40 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
|
||||
|
||||
// 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);
|
||||
|
||||
// Check message counts
|
||||
assertEquals(1, getMessageCount(b1.mId));
|
||||
assertEquals(2, getMessageCount(b2.mId));
|
||||
assertEquals(3, getMessageCount(b3.mId));
|
||||
assertEquals(0, getMessageCount(b4.mId));
|
||||
assertEquals(3, getMessageCount(bt.mId));
|
||||
|
||||
// Check the simple counting methods.
|
||||
assertEquals(3, Message.getFavoriteMessageCount(c));
|
||||
assertEquals(3, Message.getFavoriteMessageCount(c)); // excludes starred in trash
|
||||
assertEquals(2, Message.getFavoriteMessageCount(c, a1.mId));
|
||||
assertEquals(1, Message.getFavoriteMessageCount(c, a2.mId));
|
||||
assertEquals(1, Message.getFavoriteMessageCount(c, a2.mId)); // excludes starred in trash
|
||||
assertEquals(3, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_INBOX));
|
||||
assertEquals(1, Mailbox.getUnreadCountByMailboxType(c, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(4, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_INBOX));
|
||||
assertEquals(2, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(3, Mailbox.getMessageCountByMailboxType(c, Mailbox.TYPE_TRASH));
|
||||
|
||||
assertEquals(1, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_INBOX));
|
||||
assertEquals(1, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a1.mId, Mailbox.TYPE_TRASH));
|
||||
assertEquals(2, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_INBOX));
|
||||
assertEquals(0, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_OUTBOX));
|
||||
assertEquals(3, Mailbox.getUnreadCountByAccountAndMailboxType(c,
|
||||
a2.mId, Mailbox.TYPE_TRASH));
|
||||
|
||||
// 2. test for recalculateMessageCount.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user