Merge "Fix auto-refresh of mailboxes."

This commit is contained in:
Makoto Onuki 2011-02-28 16:01:47 -08:00 committed by Android (Google) Code Review
commit b02f7eb1e8
3 changed files with 12 additions and 38 deletions

View File

@ -136,8 +136,6 @@ public class MessageListFragment extends ListFragment
private int mCountTotalAccounts; private int mCountTotalAccounts;
// Misc members // Misc members
private boolean mDoAutoRefresh;
private boolean mOpenRequested; private boolean mOpenRequested;
/** Whether "Send all messages" should be shown. */ /** Whether "Send all messages" should be shown. */
@ -377,7 +375,6 @@ public class MessageListFragment extends ListFragment
mIsEasAccount = false; mIsEasAccount = false;
mIsRefreshable = false; mIsRefreshable = false;
mCountTotalAccounts = 0; mCountTotalAccounts = 0;
mDoAutoRefresh = false;
mOpenRequested = false; mOpenRequested = false;
mShowSendCommand = false; mShowSendCommand = false;
@ -934,33 +931,18 @@ public class MessageListFragment extends ListFragment
return testMultiple(mListAdapter.getSelectedSet(), MessagesAdapter.COLUMN_READ, true); return testMultiple(mListAdapter.getSelectedSet(), MessagesAdapter.COLUMN_READ, true);
} }
/**
* Called by activity to indicate that the user explicitly opened the
* mailbox and it needs auto-refresh when it's first shown. TODO:
* {@link MessageList} needs to call this as well.
*
* TODO It's a bit ugly. We can remove this if this fragment "remembers" the current mailbox ID
* through configuration changes.
*/
public void doAutoRefresh() {
mDoAutoRefresh = true;
}
/** /**
* Implements a timed refresh of "stale" mailboxes. This should only happen when * Implements a timed refresh of "stale" mailboxes. This should only happen when
* multiple conditions are true, including: * multiple conditions are true, including:
* Only refreshable mailboxes. * Only refreshable mailboxes.
* Only when the user explicitly opens the mailbox (not onResume, for example)
* Only when the mailbox is "stale" (currently set to 5 minutes since last refresh) * Only when the mailbox is "stale" (currently set to 5 minutes since last refresh)
* Note we do this even if it's a push account; even on Exchange only inbox can be pushed. * Note we do this even if it's a push account; even on Exchange only inbox can be pushed.
*/ */
private void autoRefreshStaleMailbox() { private void autoRefreshStaleMailbox() {
if (!mDoAutoRefresh // Not explicitly open if (!mIsRefreshable) {
|| !mIsRefreshable // Not refreshable (special box such as drafts, or magic boxes) // Not refreshable (special box such as drafts, or magic boxes)
) {
return; return;
} }
mDoAutoRefresh = false;
if (!mRefreshManager.isMailboxStale(mMailboxId)) { if (!mRefreshManager.isMailboxStale(mMailboxId)) {
return; return;
} }

View File

@ -206,7 +206,7 @@ public class MessageListXL extends Activity implements
} }
if (accountId != -1) { if (accountId != -1) {
mFragmentManager.selectAccount(accountId, mailboxId, messageId, true); mFragmentManager.selectAccount(accountId, mailboxId, messageId);
} }
} }
@ -418,12 +418,12 @@ public class MessageListXL extends Activity implements
private class MailboxListFragmentCallback implements MailboxListFragment.Callback { private class MailboxListFragmentCallback implements MailboxListFragment.Callback {
@Override @Override
public void onMailboxSelected(long accountId, long mailboxId) { public void onMailboxSelected(long accountId, long mailboxId) {
mFragmentManager.selectMailbox(mailboxId, -1, true); mFragmentManager.selectMailbox(mailboxId, -1);
} }
@Override @Override
public void onAccountSelected(long accountId) { public void onAccountSelected(long accountId) {
mFragmentManager.selectAccount(accountId, -1, -1, true); mFragmentManager.selectAccount(accountId, -1, -1);
loadAccounts(); // This will update the account spinner, and select the account. loadAccounts(); // This will update the account spinner, and select the account.
} }
@ -681,7 +681,7 @@ public class MessageListXL extends Activity implements
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, "Account selected: accountId=" + accountId); Log.d(Logging.LOG_TAG, "Account selected: accountId=" + accountId);
} }
mFragmentManager.selectAccount(accountId, -1, -1, true); mFragmentManager.selectAccount(accountId, -1, -1);
return true; return true;
} }
} }

View File

@ -302,7 +302,7 @@ class MessageListXLFragmentManager {
return; return;
} }
// selectAccount() calls selectMailbox/Message() if necessary. // selectAccount() calls selectMailbox/Message() if necessary.
selectAccount(accountId, mailboxId, messageId, false); selectAccount(accountId, mailboxId, messageId);
} }
private void saveMessageListFragmentState() { private void saveMessageListFragmentState() {
@ -343,11 +343,8 @@ class MessageListXLFragmentManager {
* @param accountId account ID. Must not be -1. * @param accountId account ID. Must not be -1.
* @param mailboxId mailbox ID. Pass -1 to open account's inbox. * @param mailboxId mailbox ID. Pass -1 to open account's inbox.
* @param messageId message ID. Pass -1 to not open a message. * @param messageId message ID. Pass -1 to not open a message.
* @param byExplicitUserAction set true if the user is explicitly opening the mailbox,
* in which case we perform "auto-refresh".
*/ */
public void selectAccount(long accountId, long mailboxId, long messageId, public void selectAccount(long accountId, long mailboxId, long messageId) {
boolean byExplicitUserAction) {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, "selectAccount mAccountId=" + accountId); Log.d(Logging.LOG_TAG, "selectAccount mAccountId=" + accountId);
} }
@ -373,11 +370,11 @@ class MessageListXLFragmentManager {
if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) { if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) {
// When opening the Combined view, the right pane will be "combined inbox". // When opening the Combined view, the right pane will be "combined inbox".
selectMailbox(Mailbox.QUERY_ALL_INBOXES, -1, false); selectMailbox(Mailbox.QUERY_ALL_INBOXES, -1);
} else if (mailboxId == -1) { } else if (mailboxId == -1) {
startInboxLookup(); startInboxLookup();
} else { } else {
selectMailbox(mailboxId, messageId, byExplicitUserAction); selectMailbox(mailboxId, messageId);
} }
mTargetActivity.onAccountChanged(mAccountId); mTargetActivity.onAccountChanged(mAccountId);
} }
@ -409,10 +406,8 @@ class MessageListXLFragmentManager {
* *
* @param mailboxId ID of mailbox * @param mailboxId ID of mailbox
* @param messageId message ID. Pass -1 to not open a message. * @param messageId message ID. Pass -1 to not open a message.
* @param byExplicitUserAction set true if the user is explicitly opening the mailbox,
* in which case we perform "auto-refresh".
*/ */
public void selectMailbox(long mailboxId, long messageId, boolean byExplicitUserAction) { public void selectMailbox(long mailboxId, long messageId) {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, "selectMailbox mMailboxId=" + mailboxId); Log.d(Logging.LOG_TAG, "selectMailbox mMailboxId=" + mailboxId);
} }
@ -429,9 +424,6 @@ class MessageListXLFragmentManager {
mMessageId = -1; mMessageId = -1;
// Open mailbox // Open mailbox
if (byExplicitUserAction) {
mMessageListFragment.doAutoRefresh();
}
mMessageListFragment.openMailbox(mMailboxId); mMessageListFragment.openMailbox(mMailboxId);
restoreMesasgeListState(); restoreMesasgeListState();
@ -523,7 +515,7 @@ class MessageListXLFragmentManager {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, " Found inbox"); Log.d(Logging.LOG_TAG, " Found inbox");
} }
selectMailbox(mailboxId, -1, true); selectMailbox(mailboxId, -1);
} }
@Override @Override