Merge "Add virtual mailbox for all unread messages." into jb-ub-mail-ur9

This commit is contained in:
Yu Ping Hu 2013-04-05 22:25:56 +00:00 committed by Android (Google) Code Review
commit 1389f0ed03
3 changed files with 74 additions and 44 deletions

View File

@ -35,4 +35,6 @@
<string name="mailbox_name_server_junk" translatable="false">Junk</string> <string name="mailbox_name_server_junk" translatable="false">Junk</string>
<!-- Do Not Translate. This is the system name of the "starred" folder. --> <!-- Do Not Translate. This is the system name of the "starred" folder. -->
<string name="mailbox_name_server_starred" translatable="false">Starred</string> <string name="mailbox_name_server_starred" translatable="false">Starred</string>
<!-- Do Not Translate. This is the system name of the "all unread" folder. -->
<string name="mailbox_name_server_all_unread" translatable="false">Unread</string>
</resources> </resources>

View File

@ -179,8 +179,10 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
public static final int TYPE_JUNK = 7; public static final int TYPE_JUNK = 7;
/** Search results */ /** Search results */
public static final int TYPE_SEARCH = 8; public static final int TYPE_SEARCH = 8;
/** Starred (virtual */ /** Starred (virtual) */
public static final int TYPE_STARRED = 9; public static final int TYPE_STARRED = 9;
/** All unread mail (virtual) */
public static final int TYPE_ALL_UNREAD = 10;
// Types after this are used for non-mail mailboxes (as in EAS) // Types after this are used for non-mail mailboxes (as in EAS)
public static final int TYPE_NOT_EMAIL = 0x40; public static final int TYPE_NOT_EMAIL = 0x40;
@ -254,6 +256,9 @@ public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns
case Mailbox.TYPE_STARRED: case Mailbox.TYPE_STARRED:
resId = R.string.mailbox_name_server_starred; resId = R.string.mailbox_name_server_starred;
break; break;
case Mailbox.TYPE_ALL_UNREAD:
resId = R.string.mailbox_name_server_all_unread;
break;
default: default:
throw new IllegalArgumentException("Illegal mailbox type"); throw new IllegalArgumentException("Illegal mailbox type");
} }

View File

@ -2243,6 +2243,7 @@ outer:
+ " WHEN " + Mailbox.TYPE_DRAFTS + " THEN " + R.drawable.ic_folder_drafts_holo_light + " WHEN " + Mailbox.TYPE_DRAFTS + " THEN " + R.drawable.ic_folder_drafts_holo_light
+ " WHEN " + Mailbox.TYPE_OUTBOX + " THEN " + R.drawable.ic_folder_outbox_holo_light + " WHEN " + Mailbox.TYPE_OUTBOX + " THEN " + R.drawable.ic_folder_outbox_holo_light
+ " WHEN " + Mailbox.TYPE_SENT + " THEN " + R.drawable.ic_folder_sent_holo_light + " WHEN " + Mailbox.TYPE_SENT + " THEN " + R.drawable.ic_folder_sent_holo_light
+ " WHEN " + Mailbox.TYPE_TRASH + " THEN " + R.drawable.ic_menu_trash_holo_light
+ " WHEN " + Mailbox.TYPE_STARRED + " THEN " + R.drawable.ic_menu_star_holo_light + " WHEN " + Mailbox.TYPE_STARRED + " THEN " + R.drawable.ic_menu_star_holo_light
+ " ELSE -1 END"; + " ELSE -1 END";
@ -2551,44 +2552,42 @@ outer:
long mailboxId, final boolean unseenOnly) { long mailboxId, final boolean unseenOnly) {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(UIProvider.ConversationColumns.COLOR, CONVERSATION_COLOR); values.put(UIProvider.ConversationColumns.COLOR, CONVERSATION_COLOR);
final int virtualMailboxId = getVirtualMailboxType(mailboxId);
final String[] selectionArgs;
StringBuilder sb = genSelect(getMessageListMap(), uiProjection, values); StringBuilder sb = genSelect(getMessageListMap(), uiProjection, values);
sb.append(" FROM " + Message.TABLE_NAME + " WHERE " + sb.append(" FROM " + Message.TABLE_NAME + " WHERE " +
Message.FLAG_LOADED + "=" + Message.FLAG_LOADED_COMPLETE + " AND "); Message.FLAG_LOADED + "=" + Message.FLAG_LOADED_COMPLETE + " AND ");
if (isCombinedMailbox(mailboxId)) { if (isCombinedMailbox(mailboxId)) {
switch (getVirtualMailboxType(mailboxId)) { if (unseenOnly) {
case Mailbox.TYPE_INBOX: sb.append(MessageColumns.FLAG_SEEN).append("=0 AND ");
sb.append(MessageColumns.MAILBOX_KEY + " IN (SELECT " + MailboxColumns.ID +
" FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE +
"=" + Mailbox.TYPE_INBOX + ") ");
if (unseenOnly) {
sb.append("AND ").append(MessageColumns.FLAG_SEEN).append(" = 0 ");
}
sb.append("ORDER BY " + MessageColumns.TIMESTAMP + " DESC");
break;
case Mailbox.TYPE_STARRED:
sb.append(MessageColumns.FLAG_FAVORITE + "=1 ");
if (unseenOnly) {
sb.append("AND ").append(MessageColumns.FLAG_SEEN).append(" = 0 ");
}
sb.append("ORDER BY " + MessageColumns.TIMESTAMP + " DESC");
break;
default:
throw new IllegalArgumentException("No virtual mailbox for: " + mailboxId);
} }
return db.rawQuery(sb.toString(), null); selectionArgs = null;
} else { } else {
switch (getVirtualMailboxType(mailboxId)) { if (virtualMailboxId == Mailbox.TYPE_INBOX) {
case Mailbox.TYPE_STARRED: throw new IllegalArgumentException("No virtual mailbox for: " + mailboxId);
sb.append(MessageColumns.ACCOUNT_KEY + "=? AND " +
MessageColumns.FLAG_FAVORITE + "=1 ORDER BY " +
MessageColumns.TIMESTAMP + " DESC");
break;
default:
throw new IllegalArgumentException("No virtual mailbox for: " + mailboxId);
} }
return db.rawQuery(sb.toString(), sb.append(MessageColumns.ACCOUNT_KEY).append("=? AND ");
new String[] {getVirtualMailboxAccountIdString(mailboxId)}); selectionArgs = new String[]{getVirtualMailboxAccountIdString(mailboxId)};
} }
switch (getVirtualMailboxType(mailboxId)) {
case Mailbox.TYPE_INBOX:
sb.append(MessageColumns.MAILBOX_KEY + " IN (SELECT " + MailboxColumns.ID +
" FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE +
"=" + Mailbox.TYPE_INBOX + ")");
break;
case Mailbox.TYPE_STARRED:
sb.append(MessageColumns.FLAG_FAVORITE + "=1");
break;
case Mailbox.TYPE_ALL_UNREAD:
sb.append(MessageColumns.FLAG_READ + "=0 AND " + MessageColumns.MAILBOX_KEY +
" NOT IN (SELECT " + MailboxColumns.ID + " FROM " + Mailbox.TABLE_NAME +
" WHERE " + MailboxColumns.TYPE + "=" + Mailbox.TYPE_TRASH + ")");
break;
default:
throw new IllegalArgumentException("No virtual mailbox for: " + mailboxId);
}
sb.append(" ORDER BY " + MessageColumns.TIMESTAMP + " DESC");
return db.rawQuery(sb.toString(), selectionArgs);
} }
/** /**
@ -3204,18 +3203,31 @@ outer:
SQLiteDatabase db = getDatabase(context); SQLiteDatabase db = getDatabase(context);
String id = uri.getPathSegments().get(1); String id = uri.getPathSegments().get(1);
if (id.equals(COMBINED_ACCOUNT_ID_STRING)) { if (id.equals(COMBINED_ACCOUNT_ID_STRING)) {
MatrixCursor mc = new MatrixCursorWithCachedColumns(UIProvider.FOLDERS_PROJECTION, 2); MatrixCursor mc = new MatrixCursorWithCachedColumns(UIProvider.FOLDERS_PROJECTION, 3);
Object[] row = getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_INBOX); Object[] row;
int numUnread = EmailContent.count(context, Message.CONTENT_URI, int count;
count = EmailContent.count(context, Message.CONTENT_URI,
MessageColumns.FLAG_FAVORITE + "=1", null);
row = getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_STARRED);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = count;
row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_menu_star_holo_light;
mc.addRow(row);
row = getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_ALL_UNREAD);
count = EmailContent.count(context, Message.CONTENT_URI,
MessageColumns.FLAG_READ + "=0 AND " + MessageColumns.MAILBOX_KEY +
" NOT IN (SELECT " + MailboxColumns.ID + " FROM " + Mailbox.TABLE_NAME +
" WHERE " + MailboxColumns.TYPE + "=" + Mailbox.TYPE_TRASH + ")", null);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = count;
// TODO: Hijacking the mark unread icon for now.
row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_menu_mark_unread_holo_light;
mc.addRow(row);
row = getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_INBOX);
count = EmailContent.count(context, Message.CONTENT_URI,
MessageColumns.MAILBOX_KEY + " IN (SELECT " + MailboxColumns.ID + MessageColumns.MAILBOX_KEY + " IN (SELECT " + MailboxColumns.ID +
" FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE +
"=" + Mailbox.TYPE_INBOX + ") AND " + MessageColumns.FLAG_READ + "=0", null); "=" + Mailbox.TYPE_INBOX + ") AND " + MessageColumns.FLAG_READ + "=0", null);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = numUnread; row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = count;
mc.addRow(row); row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_inbox_holo_light;
int numStarred = EmailContent.count(context, Message.CONTENT_URI,
MessageColumns.FLAG_FAVORITE + "=1", null);
row = getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_STARRED);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = numStarred;
mc.addRow(row); mc.addRow(row);
return mc; return mc;
} else { } else {
@ -3226,12 +3238,23 @@ outer:
new String[] {id}); new String[] {id});
// Add starred virtual folder to the cursor // Add starred virtual folder to the cursor
// Show number of messages as unread count (for backward compatibility) // Show number of messages as unread count (for backward compatibility)
MatrixCursor starCursor = new MatrixCursorWithCachedColumns(uiProjection, 1); MatrixCursor mc = new MatrixCursorWithCachedColumns(uiProjection, 2);
Object[] row = getVirtualMailboxRow(Long.parseLong(id), Mailbox.TYPE_STARRED); final long acctId = Long.parseLong(id);
Object[] row = getVirtualMailboxRow(acctId, Mailbox.TYPE_STARRED);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = numStarred; row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = numStarred;
row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_menu_star_holo_light; row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_menu_star_holo_light;
starCursor.addRow(row); mc.addRow(row);
Cursor[] cursors = new Cursor[] {starCursor, c}; row = getVirtualMailboxRow(acctId, Mailbox.TYPE_ALL_UNREAD);
int numUnread = EmailContent.count(context, Message.CONTENT_URI,
MessageColumns.ACCOUNT_KEY + "=" + id + " AND " +
MessageColumns.FLAG_READ + "=0 AND " + MessageColumns.MAILBOX_KEY +
" NOT IN (SELECT " + MailboxColumns.ID + " FROM " + Mailbox.TABLE_NAME +
" WHERE " + MailboxColumns.TYPE + "=" + Mailbox.TYPE_TRASH + ")", null);
row[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = numUnread;
// TODO: Hijacking the mark unread icon for now.
row[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_menu_mark_unread_holo_light;
mc.addRow(row);
Cursor[] cursors = new Cursor[] {mc, c};
return new MergeCursor(cursors); return new MergeCursor(cursors);
} }
} }