1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-26 01:28:50 -05:00

Remember last list view state when going back to a previous message list

fragment.

Fixes issue 4854.
This commit is contained in:
Danny Baumann 2013-01-30 16:45:05 +01:00
parent bfdee8161c
commit 55e5d8680e

View File

@ -27,6 +27,7 @@ import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Parcelable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.LoaderManager; import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.app.LoaderManager.LoaderCallbacks;
@ -333,8 +334,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
SORT_COMPARATORS = Collections.unmodifiableMap(map); SORT_COMPARATORS = Collections.unmodifiableMap(map);
} }
private boolean mResumed;
private ListView mListView; private ListView mListView;
private PullToRefreshListView mPullToRefreshView; private PullToRefreshListView mPullToRefreshView;
private Parcelable mSavedListState;
private int mPreviewLines = 0; private int mPreviewLines = 0;
@ -353,6 +357,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
private int mUnreadMessageCount = 0; private int mUnreadMessageCount = 0;
private Cursor[] mCursors; private Cursor[] mCursors;
private boolean[] mCursorValid;
private int mUniqueIdColumn; private int mUniqueIdColumn;
/** /**
@ -723,6 +728,12 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
return view; return view;
} }
@Override
public void onDestroyView() {
mSavedListState = mListView.onSaveInstanceState();
super.onDestroyView();
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
@ -739,8 +750,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
LoaderManager loaderManager = getLoaderManager(); LoaderManager loaderManager = getLoaderManager();
int len = mAccountUuids.length; int len = mAccountUuids.length;
mCursors = new Cursor[len]; mCursors = new Cursor[len];
mCursorValid = new boolean[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
loaderManager.initLoader(i, null, this); loaderManager.initLoader(i, null, this);
mCursorValid[i] = false;
} }
} }
@ -902,6 +915,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
@Override @Override
public void onPause() { public void onPause() {
mResumed = false;
super.onPause(); super.onPause();
mController.removeListener(mListener); mController.removeListener(mListener);
} }
@ -915,6 +929,8 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
mResumed = true;
setupFormats(); setupFormats();
Context appContext = getActivity().getApplicationContext(); Context appContext = getActivity().getApplicationContext();
@ -925,6 +941,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
LoaderManager loaderManager = getLoaderManager(); LoaderManager loaderManager = getLoaderManager();
for (int i = 0; i < mAccountUuids.length; i++) { for (int i = 0; i < mAccountUuids.length; i++) {
loaderManager.restartLoader(i, null, this); loaderManager.restartLoader(i, null, this);
mCursorValid[i] = false;
} }
// Check if we have connectivity. Cache the value. // Check if we have connectivity. Cache the value.
@ -3029,9 +3046,12 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
setPullToRefreshEnabled(true); setPullToRefreshEnabled(true);
} }
final int loaderId = loader.getId();
mCursors[loaderId] = data;
mCursorValid[loaderId] = true;
Cursor cursor; Cursor cursor;
if (mCursors.length > 1) { if (mCursors.length > 1) {
mCursors[loader.getId()] = data;
cursor = new MergeCursorWithUniqueId(mCursors, getComparator()); cursor = new MergeCursorWithUniqueId(mCursors, getComparator());
mUniqueIdColumn = cursor.getColumnIndex("_id"); mUniqueIdColumn = cursor.getColumnIndex("_id");
} else { } else {
@ -3058,6 +3078,18 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
resetActionMode(); resetActionMode();
computeBatchDirection(); computeBatchDirection();
if (mSavedListState != null && mResumed) {
boolean loadFinished = true;
for (int i = 0; i < mCursorValid.length; i++) {
loadFinished &= mCursorValid[i];
}
if (loadFinished && mSavedListState != null) {
mListView.onRestoreInstanceState(mSavedListState);
mSavedListState = null;
}
}
} }
private void cleanupSelected(Cursor cursor) { private void cleanupSelected(Cursor cursor) {