Merge "Manually restore list view state."

This commit is contained in:
Makoto Onuki 2011-06-06 17:14:04 -07:00 committed by Android (Google) Code Review
commit 63a206ea56
2 changed files with 23 additions and 11 deletions

View File

@ -20,7 +20,6 @@ import com.android.email.Controller;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.RefreshManager;
import com.android.email.activity.MailboxListFragment.Callback;
import com.android.email.provider.EmailProvider;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent.Account;
@ -811,6 +810,16 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
}
}
// Save list view state (primarily scroll position)
final ListView lv = getListView();
final Parcelable listState;
if (mSavedListState != null) {
listState = mSavedListState;
mSavedListState = null;
} else {
listState = lv.onSaveInstanceState();
}
if (cursor.getCount() == 0) {
// There's no row -- call setListShown(false) to make ListFragment show progress
// icon.
@ -840,12 +849,8 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
mDropTargetId = NO_DROP_TARGET;
mDropTargetView = null;
// Restore the state. Need to do it manually so that the position will be restored
// even after orientation changes.
if (mSavedListState != null) {
getListView().onRestoreInstanceState(mSavedListState);
mSavedListState = null;
}
// Restore the list state.
lv.onRestoreInstanceState(listState);
mIsFirstLoad = false;
}

View File

@ -1220,6 +1220,16 @@ public class MessageListFragment extends ListFragment
// Suspend message notifications as long as we're resumed
adjustMessageNotification(false);
// Save list view state (primarily scroll position)
final ListView lv = getListView();
final Parcelable listState;
if (mSavedListState != null) {
listState = mSavedListState;
mSavedListState = null;
} else {
listState = lv.onSaveInstanceState();
}
// If this is a search mailbox, set the query; otherwise, clear it
if (mMailbox != null && mMailbox.mType == Mailbox.TYPE_SEARCH) {
mListAdapter.setQuery(mMailbox.mDisplayName);
@ -1246,10 +1256,7 @@ public class MessageListFragment extends ListFragment
// Restore the state -- this step has to be the last, because Some of the
// "post processing" seems to reset the scroll position.
if (mSavedListState != null) {
getListView().onRestoreInstanceState(mSavedListState);
mSavedListState = null;
}
lv.onRestoreInstanceState(listState);
// Clear this for next reload triggered by content changed events.
mIsFirstLoad = false;