mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-12 05:00:20 -05:00
Refactor code to restore the list state
This commit is contained in:
parent
e9f57dd9c6
commit
5b8fe64917
@ -334,8 +334,6 @@ 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 Parcelable mSavedListState;
|
||||||
@ -418,6 +416,8 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
|
|
||||||
private Preferences mPreferences;
|
private Preferences mPreferences;
|
||||||
|
|
||||||
|
private boolean mLoaderJustInitialized;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to run operations that modify UI elements in the UI thread.
|
* This class is used to run operations that modify UI elements in the UI thread.
|
||||||
*
|
*
|
||||||
@ -433,6 +433,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
private static final int ACTION_PROGRESS = 3;
|
private static final int ACTION_PROGRESS = 3;
|
||||||
private static final int ACTION_REMOTE_SEARCH_FINISHED = 4;
|
private static final int ACTION_REMOTE_SEARCH_FINISHED = 4;
|
||||||
private static final int ACTION_GO_BACK = 5;
|
private static final int ACTION_GO_BACK = 5;
|
||||||
|
private static final int ACTION_RESTORE_LIST_POSITION = 6;
|
||||||
|
|
||||||
|
|
||||||
public void folderLoading(String folder, boolean loading) {
|
public void folderLoading(String folder, boolean loading) {
|
||||||
@ -471,6 +472,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
sendMessage(msg);
|
sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void restoreListPosition() {
|
||||||
|
android.os.Message msg = android.os.Message.obtain(this, ACTION_RESTORE_LIST_POSITION);
|
||||||
|
sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(android.os.Message msg) {
|
public void handleMessage(android.os.Message msg) {
|
||||||
// The following messages don't need an attached activity.
|
// The following messages don't need an attached activity.
|
||||||
@ -507,6 +513,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
mFragmentListener.goBack();
|
mFragmentListener.goBack();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case ACTION_RESTORE_LIST_POSITION: {
|
||||||
|
mListView.onRestoreInstanceState(mSavedListState);
|
||||||
|
mSavedListState = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -747,6 +758,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
|
|
||||||
restoreInstanceState(savedInstanceState);
|
restoreInstanceState(savedInstanceState);
|
||||||
|
|
||||||
|
mLoaderJustInitialized = true;
|
||||||
LoaderManager loaderManager = getLoaderManager();
|
LoaderManager loaderManager = getLoaderManager();
|
||||||
int len = mAccountUuids.length;
|
int len = mAccountUuids.length;
|
||||||
mCursors = new Cursor[len];
|
mCursors = new Cursor[len];
|
||||||
@ -915,7 +927,6 @@ 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);
|
||||||
}
|
}
|
||||||
@ -929,19 +940,21 @@ 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();
|
||||||
|
|
||||||
mSenderAboveSubject = K9.messageListSenderAboveSubject();
|
mSenderAboveSubject = K9.messageListSenderAboveSubject();
|
||||||
|
|
||||||
// Refresh the message list
|
if (!mLoaderJustInitialized) {
|
||||||
LoaderManager loaderManager = getLoaderManager();
|
// Refresh the message list
|
||||||
for (int i = 0; i < mAccountUuids.length; i++) {
|
LoaderManager loaderManager = getLoaderManager();
|
||||||
loaderManager.restartLoader(i, null, this);
|
for (int i = 0; i < mAccountUuids.length; i++) {
|
||||||
mCursorValid[i] = false;
|
loaderManager.restartLoader(i, null, this);
|
||||||
|
mCursorValid[i] = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mLoaderJustInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we have connectivity. Cache the value.
|
// Check if we have connectivity. Cache the value.
|
||||||
@ -3081,15 +3094,14 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
resetActionMode();
|
resetActionMode();
|
||||||
computeBatchDirection();
|
computeBatchDirection();
|
||||||
|
|
||||||
if (mSavedListState != null && mResumed) {
|
if (mSavedListState != null) {
|
||||||
boolean loadFinished = true;
|
boolean loadFinished = true;
|
||||||
for (int i = 0; i < mCursorValid.length; i++) {
|
for (int i = 0; i < mCursorValid.length; i++) {
|
||||||
loadFinished &= mCursorValid[i];
|
loadFinished &= mCursorValid[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadFinished && mSavedListState != null) {
|
if (loadFinished) {
|
||||||
mListView.onRestoreInstanceState(mSavedListState);
|
mHandler.restoreListPosition();
|
||||||
mSavedListState = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user