Reset fragment state when opening a new account/mailbox

Without this, there's a small window where a fragment is in a valid
state after openXxx() before the list is loaded.

Bug 3420361

Change-Id: I7f84a94dec1419762aa6b24188c023abe974d2bf
This commit is contained in:
Makoto Onuki 2011-02-22 15:09:56 -08:00
parent 3f60e9312b
commit dd123f927a
2 changed files with 53 additions and 18 deletions

View File

@ -28,6 +28,7 @@ import com.android.emailcommon.utility.Utility;
import android.app.Activity;
import android.app.ListFragment;
import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.ClipData;
import android.content.ClipDescription;
@ -74,14 +75,6 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
// The amount of time to scroll by one pixel, in ms
private static final int SCROLL_SPEED = 4;
// Colors used for drop targets
private static Integer sDropTrashColor;
private static Drawable sDropActiveDrawable;
private long mLastLoadedAccountId = -1;
private long mAccountId = -1;
private long mSelectedMailboxId = -1;
private RefreshManager mRefreshManager;
// UI Support
@ -91,9 +84,18 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
private ListView mListView;
private boolean mOpenRequested;
private boolean mResumed;
// Colors used for drop targets
private static Integer sDropTrashColor;
private static Drawable sDropActiveDrawable;
private long mLastLoadedAccountId = -1;
private long mAccountId = -1;
private long mSelectedMailboxId = -1;
private boolean mOpenRequested;
// True if a drag is currently in progress
private boolean mDragInProgress = false;
// The mailbox id of the dragged item's mailbox. We use it to prevent that box from being a
@ -194,6 +196,21 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
mCallback = (callback == null) ? EmptyCallback.INSTANCE : callback;
}
private void clearContent() {
mLastLoadedAccountId = -1;
mAccountId = -1;
mSelectedMailboxId = -1;
mOpenRequested = false;
mDragInProgress = false;
stopLoader();
if (mListAdapter != null) {
mListAdapter.swapCursor(null);
}
setListShownNoAnimation(false);
}
/**
* @param accountId the account we're looking at
*/
@ -207,6 +224,7 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
if (mAccountId == accountId) {
return;
}
clearContent();
mOpenRequested = true;
mAccountId = accountId;
if (mResumed) {
@ -322,6 +340,11 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
new MailboxListLoaderCallbacks(accountChanging));
}
private void stopLoader() {
final LoaderManager lm = getLoaderManager();
lm.destroyLoader(LOADER_ID_MAILBOX_LIST);
}
private class MailboxListLoaderCallbacks implements LoaderCallbacks<Cursor> {
private boolean mAccountChanging;

View File

@ -103,6 +103,11 @@ public class MessageListFragment extends ListFragment
private static final int LOADER_ID_MAILBOX_LOADER = 1;
private static final int LOADER_ID_MESSAGES_LOADER = 2;
// Controller access
private Controller mController;
private RefreshManager mRefreshManager;
private RefreshListener mRefreshListener = new RefreshListener();
// UI Support
private Activity mActivity;
private Callback mCallback = EmptyCallback.INSTANCE;
@ -130,16 +135,14 @@ public class MessageListFragment extends ListFragment
private boolean mIsRefreshable;
private int mCountTotalAccounts;
// Controller access
private Controller mController;
private RefreshManager mRefreshManager;
private RefreshListener mRefreshListener = new RefreshListener();
// Misc members
private boolean mDoAutoRefresh;
private boolean mOpenRequested;
/** Whether "Send all messages" should be shown. */
private boolean mShowSendCommand;
/**
* Visibility. On XL, message list is normally visible, except when message view is shown
* in full-screen on portrait.
@ -157,9 +160,6 @@ public class MessageListFragment extends ListFragment
private ActionMode mSelectionMode;
private SelectionModeCallback mLastSelectionModeCallback;
/** Whether "Send all messages" should be shown. */
private boolean mShowSendCommand;
private Utility.ListStateSaver mSavedListState;
private MessageOpenTask mMessageOpenTask;
@ -370,6 +370,17 @@ public class MessageListFragment extends ListFragment
*/
public void clearContent() {
mMailboxId = -1;
mLastLoadedMailboxId = -1;
mSelectedMessageId = -1;
mAccount = null;
mMailbox = null;
mIsEasAccount = false;
mIsRefreshable = false;
mCountTotalAccounts = 0;
mDoAutoRefresh = false;
mOpenRequested = false;
mShowSendCommand = false;
stopLoaders();
onDeselectAll();
if (mListAdapter != null) {
@ -395,10 +406,11 @@ public class MessageListFragment extends ListFragment
return;
}
clearContent();
mOpenRequested = true;
mMailboxId = mailboxId;
onDeselectAll();
if (mResumed) {
startLoading();
}