Merge "Add a mailbox type filter for syncing." into jb-ub-mail-ur10

This commit is contained in:
Yu Ping Hu 2013-10-08 18:01:22 +00:00 committed by Android (Google) Code Review
commit c39f2c4657

View File

@ -55,6 +55,10 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
* Value for {@link #SYNC_EXTRA_MAILBOX_ID} when (re)starting push. * Value for {@link #SYNC_EXTRA_MAILBOX_ID} when (re)starting push.
*/ */
public static final long SYNC_EXTRA_MAILBOX_ID_PUSH_ONLY = -3; public static final long SYNC_EXTRA_MAILBOX_ID_PUSH_ONLY = -3;
/**
* Sync extras key to specify that only a specific mailbox type should be synced.
*/
public static final String SYNC_EXTRA_MAILBOX_TYPE = "__mailboxType__";
/** /**
* Sync extras key when syncing a mailbox to specify how many additional messages to sync. * Sync extras key when syncing a mailbox to specify how many additional messages to sync.
*/ */
@ -202,6 +206,11 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
+ MailboxColumns.TYPE + "=" + Mailbox.TYPE_OUTBOX + " or " + MailboxColumns.TYPE + "=" + Mailbox.TYPE_OUTBOX + " or "
+ MailboxColumns.SYNC_INTERVAL + "=1) and " + MailboxColumns.ACCOUNT_KEY + "=?"; + MailboxColumns.SYNC_INTERVAL + "=1) and " + MailboxColumns.ACCOUNT_KEY + "=?";
/** Selection for mailboxes that are configured for sync of a certain type for an account. */
private static final String SYNCING_AND_TYPE_FOR_ACCOUNT_SELECTION =
MailboxColumns.SYNC_INTERVAL + "=1 and " + MailboxColumns.TYPE + "=? and " +
MailboxColumns.ACCOUNT_KEY + "=?";
// Types of mailboxes. The list is ordered to match a typical UI presentation, e.g. // Types of mailboxes. The list is ordered to match a typical UI presentation, e.g.
// placing the inbox at the top. // placing the inbox at the top.
// Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on // Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on
@ -818,6 +827,19 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
new String[] { Long.toString(accountId) }, MailboxColumns.TYPE + " ASC"); new String[] { Long.toString(accountId) }, MailboxColumns.TYPE + " ASC");
} }
/**
* Get the mailbox ids for an account that are configured for sync and have a specific type.
* @param accountId The id for the account that is syncing.
* @param mailboxType The type of the mailbox we're interested in.
* @return A cursor (with one column, containing ids) with all mailbox ids that match.
*/
public static Cursor getMailboxIdsForSyncByType(final ContentResolver cr, final long accountId,
final int mailboxType) {
return cr.query(Mailbox.CONTENT_URI, Mailbox.ID_PROJECTION,
SYNCING_AND_TYPE_FOR_ACCOUNT_SELECTION,
new String[] { Integer.toString(mailboxType), Long.toString(accountId) }, null);
}
/** /**
* Get the account id for a mailbox. * Get the account id for a mailbox.
* @param context The {@link Context}. * @param context The {@link Context}.