Merge "Pass projection into getVirtualMailboxRow() and getVirtualMailboxCursor()" into ub-mail-master

This commit is contained in:
Tony Mantler 2013-12-09 18:45:58 +00:00 committed by Android (Google) Code Review
commit 471e792ab4

View File

@ -3420,48 +3420,44 @@ public class EmailProvider extends ContentProvider {
UIProvider.ConversationListIcon.NONE; UIProvider.ConversationListIcon.NONE;
} }
// TODO: Pass in projection b/10912870 private Cursor getVirtualMailboxCursor(long mailboxId, String[] projection) {
private Cursor getVirtualMailboxCursor(long mailboxId) { MatrixCursor mc = new MatrixCursorWithCachedColumns(projection, 1);
MatrixCursor mc = new MatrixCursorWithCachedColumns(UIProvider.FOLDERS_PROJECTION, 1);
mc.addRow(getVirtualMailboxRow(getVirtualMailboxAccountId(mailboxId), mc.addRow(getVirtualMailboxRow(getVirtualMailboxAccountId(mailboxId),
getVirtualMailboxType(mailboxId))); getVirtualMailboxType(mailboxId), projection));
return mc; return mc;
} }
// TODO: Pass in projection b/10912870 private Object[] getVirtualMailboxRow(long accountId, int mailboxType, String[] projection) {
private Object[] getVirtualMailboxRow(long accountId, int mailboxType) {
final long id = getVirtualMailboxId(accountId, mailboxType); final long id = getVirtualMailboxId(accountId, mailboxType);
final String idString = Long.toString(id); final String idString = Long.toString(id);
Object[] values = new Object[UIProvider.FOLDERS_PROJECTION.length]; Object[] values = new Object[projection.length];
values[UIProvider.FOLDER_ID_COLUMN] = id; // Not all column values are filled in here, as some are not applicable to virtual mailboxes
values[UIProvider.FOLDER_URI_COLUMN] = combinedUriString("uifolder", idString); // The remainder are left null
values[UIProvider.FOLDER_NAME_COLUMN] = getFolderDisplayName( for (int i = 0; i < projection.length; i++) {
getFolderTypeFromMailboxType(mailboxType), ""); final String column = projection[i];
if (column.equals(UIProvider.FolderColumns._ID)) {
values[i] = id;
} else if (column.equals(UIProvider.FolderColumns.URI)) {
values[i] = combinedUriString("uifolder", idString);
} else if (column.equals(UIProvider.FolderColumns.NAME)) {
// default empty string since all of these should use resource strings // default empty string since all of these should use resource strings
values[UIProvider.FOLDER_HAS_CHILDREN_COLUMN] = 0; values[i] = getFolderDisplayName(getFolderTypeFromMailboxType(mailboxType), "");
values[UIProvider.FOLDER_CAPABILITIES_COLUMN] = } else if (column.equals(UIProvider.FolderColumns.HAS_CHILDREN)) {
UIProvider.FolderCapabilities.DELETE | UIProvider.FolderCapabilities.IS_VIRTUAL; values[i] = 0;
values[UIProvider.FOLDER_CONVERSATION_LIST_URI_COLUMN] = combinedUriString("uimessages", } else if (column.equals(UIProvider.FolderColumns.CAPABILITIES)) {
idString); values[i] = UIProvider.FolderCapabilities.DELETE
| UIProvider.FolderCapabilities.IS_VIRTUAL;
// Do any special handling } else if (column.equals(UIProvider.FolderColumns.CONVERSATION_LIST_URI)) {
final String accountIdString = Long.toString(accountId); values[i] = combinedUriString("uimessages", idString);
switch (mailboxType) { } else if (column.equals(UIProvider.FolderColumns.UNREAD_COUNT)) {
case Mailbox.TYPE_INBOX: if (mailboxType == Mailbox.TYPE_INBOX && accountId == COMBINED_ACCOUNT_ID) {
if (accountId == COMBINED_ACCOUNT_ID) {
// Add the unread count
final int unreadCount = EmailContent.count(getContext(), Message.CONTENT_URI, final int unreadCount = EmailContent.count(getContext(), 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", + "=" + Mailbox.TYPE_INBOX + ") AND " + MessageColumns.FLAG_READ + "=0",
null); null);
values[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = unreadCount; values[i] = unreadCount;
} } else if (mailboxType == Mailbox.TYPE_UNREAD) {
// Add the icon
values[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_inbox;
break;
case Mailbox.TYPE_UNREAD: {
// Add the unread count
final String accountKeyClause; final String accountKeyClause;
final String[] whereArgs; final String[] whereArgs;
if (accountId == COMBINED_ACCOUNT_ID) { if (accountId == COMBINED_ACCOUNT_ID) {
@ -3469,19 +3465,15 @@ public class EmailProvider extends ContentProvider {
whereArgs = null; whereArgs = null;
} else { } else {
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND "; accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
whereArgs = new String[] { accountIdString }; whereArgs = new String[] { Long.toString(accountId) };
} }
final int unreadCount = EmailContent.count(getContext(), Message.CONTENT_URI, final int unreadCount = EmailContent.count(getContext(), Message.CONTENT_URI,
accountKeyClause + MessageColumns.FLAG_READ + "=0 AND " accountKeyClause + MessageColumns.FLAG_READ + "=0 AND "
+ MessageColumns.MAILBOX_KEY + " NOT IN (SELECT " + MailboxColumns.ID + MessageColumns.MAILBOX_KEY + " NOT IN (SELECT " + MailboxColumns.ID
+ " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + "=" + " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + "="
+ Mailbox.TYPE_TRASH + ")", whereArgs); + Mailbox.TYPE_TRASH + ")", whereArgs);
values[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = unreadCount; values[i] = unreadCount;
// Add the icon } else if (mailboxType == Mailbox.TYPE_STARRED) {
values[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_unread;
break;
} case Mailbox.TYPE_STARRED: {
// Add the starred count as the unread count
final String accountKeyClause; final String accountKeyClause;
final String[] whereArgs; final String[] whereArgs;
if (accountId == COMBINED_ACCOUNT_ID) { if (accountId == COMBINED_ACCOUNT_ID) {
@ -3489,17 +3481,22 @@ public class EmailProvider extends ContentProvider {
whereArgs = null; whereArgs = null;
} else { } else {
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND "; accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
whereArgs = new String[] { accountIdString }; whereArgs = new String[] { Long.toString(accountId) };
} }
final int starredCount = EmailContent.count(getContext(), Message.CONTENT_URI, final int starredCount = EmailContent.count(getContext(), Message.CONTENT_URI,
accountKeyClause + MessageColumns.FLAG_FAVORITE + "=1", whereArgs); accountKeyClause + MessageColumns.FLAG_FAVORITE + "=1", whereArgs);
values[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = starredCount; values[i] = starredCount;
// Add the icon }
values[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_star; } else if (column.equals(UIProvider.FolderColumns.ICON_RES_ID)) {
break; if (mailboxType == Mailbox.TYPE_INBOX) {
values[i] = R.drawable.ic_folder_inbox;
} else if (mailboxType == Mailbox.TYPE_UNREAD) {
values[i] = R.drawable.ic_folder_unread;
} else if (mailboxType == Mailbox.TYPE_STARRED) {
values[i] = R.drawable.ic_folder_star;
}
} }
} }
return values; return values;
} }
@ -3690,13 +3687,14 @@ public class EmailProvider extends ContentProvider {
final MatrixCursor mc = new MatrixCursorWithCachedColumns(uiProjection); final MatrixCursor mc = new MatrixCursorWithCachedColumns(uiProjection);
if (id.equals(COMBINED_ACCOUNT_ID_STRING)) { if (id.equals(COMBINED_ACCOUNT_ID_STRING)) {
mc.addRow(getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_INBOX)); mc.addRow(getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_INBOX, uiProjection));
mc.addRow(getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_STARRED)); mc.addRow(
mc.addRow(getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_UNREAD)); getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_STARRED, uiProjection));
mc.addRow(getVirtualMailboxRow(COMBINED_ACCOUNT_ID, Mailbox.TYPE_UNREAD, uiProjection));
} else { } else {
final long acctId = Long.parseLong(id); final long acctId = Long.parseLong(id);
mc.addRow(getVirtualMailboxRow(acctId, Mailbox.TYPE_STARRED)); mc.addRow(getVirtualMailboxRow(acctId, Mailbox.TYPE_STARRED, uiProjection));
mc.addRow(getVirtualMailboxRow(acctId, Mailbox.TYPE_UNREAD)); mc.addRow(getVirtualMailboxRow(acctId, Mailbox.TYPE_UNREAD, uiProjection));
} }
return mc; return mc;
@ -4327,7 +4325,7 @@ public class EmailProvider extends ContentProvider {
case UI_FOLDER: case UI_FOLDER:
mailboxId = Long.parseLong(id); mailboxId = Long.parseLong(id);
if (isVirtualMailbox(mailboxId)) { if (isVirtualMailbox(mailboxId)) {
c = getVirtualMailboxCursor(mailboxId); c = getVirtualMailboxCursor(mailboxId, uiProjection);
notifyUri = UIPROVIDER_FOLDER_NOTIFIER.buildUpon().appendPath(id).build(); notifyUri = UIPROVIDER_FOLDER_NOTIFIER.buildUpon().appendPath(id).build();
} else { } else {
c = db.rawQuery(genQueryMailbox(uiProjection, id), new String[]{id}); c = db.rawQuery(genQueryMailbox(uiProjection, id), new String[]{id});