Merge "Pass projection into getVirtualMailboxRow() and getVirtualMailboxCursor()" into ub-mail-master
This commit is contained in:
commit
471e792ab4
@ -3420,86 +3420,83 @@ 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) {
|
||||||
|
final String accountKeyClause;
|
||||||
|
final String[] whereArgs;
|
||||||
|
if (accountId == COMBINED_ACCOUNT_ID) {
|
||||||
|
accountKeyClause = "";
|
||||||
|
whereArgs = null;
|
||||||
|
} else {
|
||||||
|
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
|
||||||
|
whereArgs = new String[] { Long.toString(accountId) };
|
||||||
|
}
|
||||||
|
final int unreadCount = EmailContent.count(getContext(), Message.CONTENT_URI,
|
||||||
|
accountKeyClause + MessageColumns.FLAG_READ + "=0 AND "
|
||||||
|
+ MessageColumns.MAILBOX_KEY + " NOT IN (SELECT " + MailboxColumns.ID
|
||||||
|
+ " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + "="
|
||||||
|
+ Mailbox.TYPE_TRASH + ")", whereArgs);
|
||||||
|
values[i] = unreadCount;
|
||||||
|
} else if (mailboxType == Mailbox.TYPE_STARRED) {
|
||||||
|
final String accountKeyClause;
|
||||||
|
final String[] whereArgs;
|
||||||
|
if (accountId == COMBINED_ACCOUNT_ID) {
|
||||||
|
accountKeyClause = "";
|
||||||
|
whereArgs = null;
|
||||||
|
} else {
|
||||||
|
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
|
||||||
|
whereArgs = new String[] { Long.toString(accountId) };
|
||||||
|
}
|
||||||
|
final int starredCount = EmailContent.count(getContext(), Message.CONTENT_URI,
|
||||||
|
accountKeyClause + MessageColumns.FLAG_FAVORITE + "=1", whereArgs);
|
||||||
|
values[i] = starredCount;
|
||||||
}
|
}
|
||||||
// Add the icon
|
} else if (column.equals(UIProvider.FolderColumns.ICON_RES_ID)) {
|
||||||
values[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_inbox;
|
if (mailboxType == Mailbox.TYPE_INBOX) {
|
||||||
break;
|
values[i] = R.drawable.ic_folder_inbox;
|
||||||
case Mailbox.TYPE_UNREAD: {
|
} else if (mailboxType == Mailbox.TYPE_UNREAD) {
|
||||||
// Add the unread count
|
values[i] = R.drawable.ic_folder_unread;
|
||||||
final String accountKeyClause;
|
} else if (mailboxType == Mailbox.TYPE_STARRED) {
|
||||||
final String[] whereArgs;
|
values[i] = R.drawable.ic_folder_star;
|
||||||
if (accountId == COMBINED_ACCOUNT_ID) {
|
|
||||||
accountKeyClause = "";
|
|
||||||
whereArgs = null;
|
|
||||||
} else {
|
|
||||||
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
|
|
||||||
whereArgs = new String[] { accountIdString };
|
|
||||||
}
|
}
|
||||||
final int unreadCount = EmailContent.count(getContext(), Message.CONTENT_URI,
|
|
||||||
accountKeyClause + MessageColumns.FLAG_READ + "=0 AND "
|
|
||||||
+ MessageColumns.MAILBOX_KEY + " NOT IN (SELECT " + MailboxColumns.ID
|
|
||||||
+ " FROM " + Mailbox.TABLE_NAME + " WHERE " + MailboxColumns.TYPE + "="
|
|
||||||
+ Mailbox.TYPE_TRASH + ")", whereArgs);
|
|
||||||
values[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = unreadCount;
|
|
||||||
// Add the icon
|
|
||||||
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[] whereArgs;
|
|
||||||
if (accountId == COMBINED_ACCOUNT_ID) {
|
|
||||||
accountKeyClause = "";
|
|
||||||
whereArgs = null;
|
|
||||||
} else {
|
|
||||||
accountKeyClause = MessageColumns.ACCOUNT_KEY + "= ? AND ";
|
|
||||||
whereArgs = new String[] { accountIdString };
|
|
||||||
}
|
|
||||||
final int starredCount = EmailContent.count(getContext(), Message.CONTENT_URI,
|
|
||||||
accountKeyClause + MessageColumns.FLAG_FAVORITE + "=1", whereArgs);
|
|
||||||
values[UIProvider.FOLDER_UNREAD_COUNT_COLUMN] = starredCount;
|
|
||||||
// Add the icon
|
|
||||||
values[UIProvider.FOLDER_ICON_RES_ID_COLUMN] = R.drawable.ic_folder_star;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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});
|
||||||
|
Loading…
Reference in New Issue
Block a user