From dc33d50a244f2b455e75f55f8b64add37093fce5 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 28 Sep 2010 15:23:39 -0700 Subject: [PATCH] Don't restore list view state when changing mailbox. Bug 3015916 Change-Id: I4b368f511a94ec83723b571d1cfca1b3d39e4d04 --- .../email/activity/MessageListFragment.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/com/android/email/activity/MessageListFragment.java b/src/com/android/email/activity/MessageListFragment.java index 7f06cdcd2..1e028cf7b 100644 --- a/src/com/android/email/activity/MessageListFragment.java +++ b/src/com/android/email/activity/MessageListFragment.java @@ -843,11 +843,15 @@ public class MessageListFragment extends ListFragment final LoaderManager lm = getLoaderManager(); // If we're loading a different mailbox, discard the previous result. + // It also causes not to preserve the list position. + boolean mailboxChanging = false; if ((mLastLoadedMailboxId != -1) && (mLastLoadedMailboxId != mMailboxId)) { + mailboxChanging = true; lm.stopLoader(LOADER_ID_MAILBOX_LOADER); lm.stopLoader(LOADER_ID_MESSAGES_LOADER); } - lm.initLoader(LOADER_ID_MAILBOX_LOADER, null, new MailboxAccountLoaderCallback()); + lm.initLoader(LOADER_ID_MAILBOX_LOADER, null, + new MailboxAccountLoaderCallback(mailboxChanging)); } /** @@ -855,6 +859,12 @@ public class MessageListFragment extends ListFragment */ private class MailboxAccountLoaderCallback implements LoaderManager.LoaderCallbacks< MailboxAccountLoader.Result> { + private final boolean mMailboxChanging; + + public MailboxAccountLoaderCallback(boolean mailboxChanging) { + mMailboxChanging = mailboxChanging; + } + @Override public Loader onCreateLoader(int id, Bundle args) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { @@ -882,7 +892,7 @@ public class MessageListFragment extends ListFragment mIsEasAccount = result.mIsEasAccount; mIsRefreshable = result.mIsRefreshable; getLoaderManager().initLoader(LOADER_ID_MESSAGES_LOADER, null, - new MessagesLoaderCallback()); + new MessagesLoaderCallback(mMailboxChanging)); } } @@ -891,13 +901,19 @@ public class MessageListFragment extends ListFragment */ private void refreshList() { getLoaderManager().restartLoader(LOADER_ID_MESSAGES_LOADER, null, - new MessagesLoaderCallback()); + new MessagesLoaderCallback(false)); } /** * Loader callbacks for message list. */ private class MessagesLoaderCallback implements LoaderManager.LoaderCallbacks { + private final boolean mMailboxChanging; + + public MessagesLoaderCallback(boolean mailboxChanging) { + mMailboxChanging = mailboxChanging; + } + @Override public Loader onCreateLoader(int id, Bundle args) { if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { @@ -918,7 +934,9 @@ public class MessageListFragment extends ListFragment // Save list view state (primarily scroll position) final ListView lv = getListView(); final Utility.ListStateSaver lss; - if (mSavedListState != null) { + if (mMailboxChanging) { + lss = null; // Don't preserve list state + } else if (mSavedListState != null) { lss = mSavedListState; mSavedListState = null; } else { @@ -938,9 +956,11 @@ public class MessageListFragment extends ListFragment showSendPanelIfNecessary(); highlightSelectedMessage(); - // Restore the state -- it has to be the last. - // (Some of the "post processing" resets the state.) - lss.restore(lv); + // Restore the state -- this step has to be the last, because Some of the + // "post processing" seems to reset the scroll position. + if (lss != null) { + lss.restore(lv); + } resetNewMessageCount(mActivity, mMailboxId, getAccountId()); }