mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Remember last list view state when going back to a previous message list
fragment. Fixes issue 4854.
This commit is contained in:
parent
bfdee8161c
commit
55e5d8680e
@ -27,6 +27,7 @@ import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.app.LoaderManager.LoaderCallbacks;
|
||||
@ -333,8 +334,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
SORT_COMPARATORS = Collections.unmodifiableMap(map);
|
||||
}
|
||||
|
||||
private boolean mResumed;
|
||||
|
||||
private ListView mListView;
|
||||
private PullToRefreshListView mPullToRefreshView;
|
||||
private Parcelable mSavedListState;
|
||||
|
||||
private int mPreviewLines = 0;
|
||||
|
||||
@ -353,6 +357,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
private int mUnreadMessageCount = 0;
|
||||
|
||||
private Cursor[] mCursors;
|
||||
private boolean[] mCursorValid;
|
||||
private int mUniqueIdColumn;
|
||||
|
||||
/**
|
||||
@ -723,6 +728,12 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
mSavedListState = mListView.onSaveInstanceState();
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
@ -739,8 +750,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
LoaderManager loaderManager = getLoaderManager();
|
||||
int len = mAccountUuids.length;
|
||||
mCursors = new Cursor[len];
|
||||
mCursorValid = new boolean[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
loaderManager.initLoader(i, null, this);
|
||||
mCursorValid[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -902,6 +915,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mResumed = false;
|
||||
super.onPause();
|
||||
mController.removeListener(mListener);
|
||||
}
|
||||
@ -915,6 +929,8 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
mResumed = true;
|
||||
|
||||
setupFormats();
|
||||
|
||||
Context appContext = getActivity().getApplicationContext();
|
||||
@ -925,6 +941,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
LoaderManager loaderManager = getLoaderManager();
|
||||
for (int i = 0; i < mAccountUuids.length; i++) {
|
||||
loaderManager.restartLoader(i, null, this);
|
||||
mCursorValid[i] = false;
|
||||
}
|
||||
|
||||
// Check if we have connectivity. Cache the value.
|
||||
@ -3029,9 +3046,12 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
setPullToRefreshEnabled(true);
|
||||
}
|
||||
|
||||
final int loaderId = loader.getId();
|
||||
mCursors[loaderId] = data;
|
||||
mCursorValid[loaderId] = true;
|
||||
|
||||
Cursor cursor;
|
||||
if (mCursors.length > 1) {
|
||||
mCursors[loader.getId()] = data;
|
||||
cursor = new MergeCursorWithUniqueId(mCursors, getComparator());
|
||||
mUniqueIdColumn = cursor.getColumnIndex("_id");
|
||||
} else {
|
||||
@ -3058,6 +3078,18 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
|
||||
resetActionMode();
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user