Merge "Fix where recent mailboxes are displayed"

This commit is contained in:
Todd Kennedy 2011-06-08 15:47:49 -07:00 committed by Android (Google) Code Review
commit 7986cf6737
3 changed files with 38 additions and 27 deletions

View File

@ -78,12 +78,6 @@ public class AccountSelectorAdapter extends CursorAdapter {
ACCOUNT_POSITION,
};
/** Mailbox types for default "recent mailbox" entries if none exist */
private static final int[] DEFAULT_RECENT_TYPES = new int[] {
Mailbox.TYPE_DRAFTS,
Mailbox.TYPE_SENT,
};
/** Sort order. Show the default account first. */
private static final String ORDER_BY =
EmailContent.Account.IS_DEFAULT + " desc, " + EmailContent.Account.RECORD_ID;
@ -323,28 +317,18 @@ public class AccountSelectorAdapter extends CursorAdapter {
emailAddress =
matrixCursor.getString(matrixCursor.getColumnIndex(Account.EMAIL_ADDRESS));
}
boolean useTwoPane = UiUtilities.useTwoPane(mContext);
// Filter system mailboxes if we're using a two-pane view
RecentMailboxManager mailboxManager = RecentMailboxManager.getInstance(mContext);
// TODO Verify proper behaviour with Rich. The default recent list may be added to the
// database, which would mean this special code goes away.
ArrayList<Long> recentMailboxes = mailboxManager.getMostRecent(mAccountId, useTwoPane);
if (!useTwoPane && recentMailboxes.size() == 0) {
for (int type : DEFAULT_RECENT_TYPES) {
Mailbox mailbox = Mailbox.restoreMailboxOfType(mContext, mAccountId, type);
if (mailbox != null) {
recentMailboxes.add(mailbox.mId);
}
}
ArrayList<Long> recentMailboxes = null;
boolean useTwoPane = UiUtilities.useTwoPane(mContext);
if (!useTwoPane) {
// Do not display recent mailboxes in the account spinner for the two pane view
recentMailboxes = mailboxManager.getMostRecent(mAccountId, useTwoPane);
}
matrixCursor.mRecentCount = recentMailboxes.size();
if (!useTwoPane || recentMailboxes.size() > 0) {
// Always have a header for one pane; optional on two pane
if (recentMailboxes != null && recentMailboxes.size() > 0) {
matrixCursor.mRecentCount = recentMailboxes.size();
String mailboxHeader = mContext.getString(
R.string.mailbox_list_account_selector_mailbox_header_fmt, emailAddress);
addRow(matrixCursor, ROW_TYPE_HEADER, 0L, mailboxHeader, null, 0, UNKNOWN_POSITION);
}
if (recentMailboxes.size() > 0) {
for (long mailboxId : recentMailboxes) {
final int unread = Utility.getFirstRowInt(mContext,
ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId),

View File

@ -583,9 +583,13 @@ class MailboxFragmentAdapter extends CursorAdapter {
final String name = mContext.getString(R.string.mailbox_list_user_mailboxes);
addMailboxRow(headerCursor, 0L, name, 0, 0, 0, ROW_TYPE_HEADER, 0, 0L);
}
ArrayList<Long> recentList =
RecentMailboxManager.getInstance(mContext).getMostRecent(mAccountId, true);
if (recentList.size() > 0) {
ArrayList<Long> recentList = null;
boolean useTwoPane = UiUtilities.useTwoPane(mContext);
if (useTwoPane) {
recentList = RecentMailboxManager.getInstance(mContext)
.getMostRecent(mAccountId, true);
}
if (recentList != null && recentList.size() > 0) {
final String name = mContext.getString(R.string.mailbox_list_recent_mailboxes);
addMailboxRow(recentCursor, 0L, name, 0, 0, 0, ROW_TYPE_HEADER, 0, 0L);
for (long mailboxId : recentList) {

View File

@ -62,6 +62,12 @@ public class RecentMailboxManager {
+ " LIMIT ? )";
private final Context mContext;
/** Mailbox types for default "recent mailbox" entries if none exist */
private static final int[] DEFAULT_RECENT_TYPES = new int[] {
Mailbox.TYPE_DRAFTS,
Mailbox.TYPE_SENT,
};
public static synchronized RecentMailboxManager getInstance(Context context) {
if (sInstance == null) {
sInstance = new RecentMailboxManager(context);
@ -80,7 +86,9 @@ public class RecentMailboxManager {
}
/**
* Gets the most recently touched mailboxes for the specified account.
* Gets the most recently touched mailboxes for the specified account. If there are no
* recent mailboxes and withExclusions is {@code false}, default recent mailboxes will
* be returned.
* <p><em>WARNING</em>: This method blocks on the database.
* @param accountId The ID of the account to load the recent list.
* @param withExclusions If {@code false}, all mailboxes are eligible for the recent list.
@ -101,6 +109,21 @@ public class RecentMailboxManager {
} finally {
cursor.close();
}
if (returnList.size() == 0 && !withExclusions) {
returnList = getDefaultMostRecent(accountId);
}
return returnList;
}
/** Gets the default recent mailbox list. */
private ArrayList<Long> getDefaultMostRecent(long accountId) {
ArrayList<Long> returnList = new ArrayList<Long>();
for (int type : DEFAULT_RECENT_TYPES) {
Mailbox mailbox = Mailbox.restoreMailboxOfType(mContext, accountId, type);
if (mailbox != null) {
returnList.add(mailbox.mId);
}
}
return returnList;
}