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;
// Misc members
private boolean mDoAutoRefresh;
private boolean mOpenRequested;
/** Whether "Send all messages" should be shown. */
@ -377,7 +375,6 @@ public class MessageListFragment extends ListFragment
mIsEasAccount = false;
mIsRefreshable = false;
mCountTotalAccounts = 0;
mDoAutoRefresh = false;
mOpenRequested = false;
mShowSendCommand = false;
@ -934,33 +931,18 @@ public class MessageListFragment extends ListFragment
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
* multiple conditions are true, including:
* 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)
* Note we do this even if it's a push account; even on Exchange only inbox can be pushed.
*/
private void autoRefreshStaleMailbox() {
if (!mDoAutoRefresh // Not explicitly open
|| !mIsRefreshable // Not refreshable (special box such as drafts, or magic boxes)
) {
if (!mIsRefreshable) {
// Not refreshable (special box such as drafts, or magic boxes)
return;
}
mDoAutoRefresh = false;
if (!mRefreshManager.isMailboxStale(mMailboxId)) {
return;
}

View File

@ -206,7 +206,7 @@ public class MessageListXL extends Activity implements
}
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 {
@Override
public void onMailboxSelected(long accountId, long mailboxId) {
mFragmentManager.selectMailbox(mailboxId, -1, true);
mFragmentManager.selectMailbox(mailboxId, -1);
}
@Override
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.
}
@ -681,7 +681,7 @@ public class MessageListXL extends Activity implements
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, "Account selected: accountId=" + accountId);
}
mFragmentManager.selectAccount(accountId, -1, -1, true);
mFragmentManager.selectAccount(accountId, -1, -1);
return true;
}
}

View File

@ -302,7 +302,7 @@ class MessageListXLFragmentManager {
return;
}
// selectAccount() calls selectMailbox/Message() if necessary.
selectAccount(accountId, mailboxId, messageId, false);
selectAccount(accountId, mailboxId, messageId);
}
private void saveMessageListFragmentState() {
@ -343,11 +343,8 @@ class MessageListXLFragmentManager {
* @param accountId account ID. Must not be -1.
* @param mailboxId mailbox ID. Pass -1 to open account's inbox.
* @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,
boolean byExplicitUserAction) {
public void selectAccount(long accountId, long mailboxId, long messageId) {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, "selectAccount mAccountId=" + accountId);
}
@ -373,11 +370,11 @@ class MessageListXLFragmentManager {
if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == -1)) {
// 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) {
startInboxLookup();
} else {
selectMailbox(mailboxId, messageId, byExplicitUserAction);
selectMailbox(mailboxId, messageId);
}
mTargetActivity.onAccountChanged(mAccountId);
}
@ -409,10 +406,8 @@ class MessageListXLFragmentManager {
*
* @param mailboxId ID of mailbox
* @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) {
Log.d(Logging.LOG_TAG, "selectMailbox mMailboxId=" + mailboxId);
}
@ -429,9 +424,6 @@ class MessageListXLFragmentManager {
mMessageId = -1;
// Open mailbox
if (byExplicitUserAction) {
mMessageListFragment.doAutoRefresh();
}
mMessageListFragment.openMailbox(mMailboxId);
restoreMesasgeListState();
@ -523,7 +515,7 @@ class MessageListXLFragmentManager {
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
Log.d(Logging.LOG_TAG, " Found inbox");
}
selectMailbox(mailboxId, -1, true);
selectMailbox(mailboxId, -1);
}
@Override