Merged activity step1: Use FragmentTransaction (tablet)
Change-Id: Ia67e7f3e0658cb962d328c10affe11ccb5a165ea
This commit is contained in:
parent
8f84cae3c3
commit
38a33bd28f
|
@ -23,8 +23,7 @@
|
|||
android:splitMotionEvents="true"
|
||||
>
|
||||
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MailboxListFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/left_pane"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -34,8 +33,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MessageListFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/middle_pane"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="0dip"
|
||||
|
@ -46,8 +44,7 @@
|
|||
android:id="@+id/message_command_buttons"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MessageViewFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/right_pane"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -23,15 +23,12 @@
|
|||
android:splitMotionEvents="true"
|
||||
>
|
||||
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MailboxListFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/left_pane"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MessageListFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/middle_pane"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -46,8 +43,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<fragment
|
||||
android:name="com.android.email.activity.MessageViewFragment"
|
||||
<FrameLayout
|
||||
android:id="@+id/right_pane"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MailboxList extends Activity implements MailboxListFragment.Callbac
|
|||
|
||||
mActionBar.setTitle(R.string.mailbox_list_title);
|
||||
mListFragment.setCallback(this);
|
||||
mListFragment.openMailboxes(mAccountId);
|
||||
mListFragment.openMailboxes(mAccountId, false);
|
||||
|
||||
// Halt the progress indicator (we'll display it later when needed)
|
||||
setProgressBarIndeterminate(true);
|
||||
|
|
|
@ -64,6 +64,9 @@ import java.util.TimerTask;
|
|||
* - pass-through implementations of onCreateContextMenu() and onContextItemSelected() (temporary)
|
||||
*
|
||||
* TODO Restoring ListView state -- don't do this when changing accounts
|
||||
* TODO Restoring scroll position on screen rotation is broken.
|
||||
* TODO Remove clearContent -> most probably this is the cause for the scroll position not being
|
||||
* restored issue.
|
||||
*/
|
||||
public class MailboxListFragment extends ListFragment implements OnItemClickListener,
|
||||
OnDragListener {
|
||||
|
@ -81,9 +84,14 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
private static final int SCROLL_ZONE_SIZE = 64;
|
||||
// The amount of time to scroll by one pixel, in ms
|
||||
private static final int SCROLL_SPEED = 4;
|
||||
|
||||
/** Arbitrary number for use with the loader manager */
|
||||
private static final int MAILBOX_LOADER_ID = 1;
|
||||
|
||||
/** Argument name(s) */
|
||||
private static final String ARG_ACCOUNT_ID = "accountId";
|
||||
private static final String ARG_FORCE_RELOAD = "forceReload";
|
||||
|
||||
// TODO Clean up usage of mailbox ID. We use both '-1' and '0' to mean "not selected". To
|
||||
// confuse matters, the database uses '-1' for "no mailbox" and '0' for "invalid mailbox".
|
||||
// Once legacy accounts properly support nested folders, we need to make sure we're only
|
||||
|
@ -198,6 +206,18 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
return NO_DROP_TARGET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with initialization parameters.
|
||||
*/
|
||||
public static MailboxListFragment newInstance(long accountId, boolean forceReload) {
|
||||
final MailboxListFragment instance = new MailboxListFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putLong(ARG_ACCOUNT_ID, accountId);
|
||||
args.putBoolean(ARG_FORCE_RELOAD, forceReload);
|
||||
instance.setArguments(args);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to do initial creation of a fragment. This is called after
|
||||
* {@link #onAttach(Activity)} and before {@link #onActivityCreated(Bundle)}.
|
||||
|
@ -240,6 +260,9 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
mListView.setOnDragListener(this);
|
||||
registerForContextMenu(mListView);
|
||||
|
||||
final Bundle args = getArguments();
|
||||
openMailboxes(args.getLong(ARG_ACCOUNT_ID), args.getBoolean(ARG_FORCE_RELOAD));
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
|
@ -264,16 +287,6 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
setListShownNoAnimation(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the top-level mailboxes for the given account ID. If the account is currently
|
||||
* loaded, no actions will be performed. To forcefully load the list of top-level
|
||||
* mailboxes use {@link #openMailboxes(long, boolean)}
|
||||
* @param accountId The ID of the account we want to view
|
||||
*/
|
||||
public void openMailboxes(long accountId) {
|
||||
openMailboxes(accountId, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the top-level mailboxes for the given account ID. If the account is currently
|
||||
* loaded, the list of top-level mailbox will not be reloaded unless <code>forceReload</code>
|
||||
|
@ -282,7 +295,8 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
* @param forceReload If <code>true</code>, always load the list of top-level mailboxes.
|
||||
* Otherwise, only load the list of top-level mailboxes if the account changes.
|
||||
*/
|
||||
public void openMailboxes(long accountId, boolean forceReload) {
|
||||
// STOPSHIP Make it private once phone activities are gone
|
||||
void openMailboxes(long accountId, boolean forceReload) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MailboxListFragment openMailboxes");
|
||||
}
|
||||
|
@ -413,6 +427,9 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
}
|
||||
|
||||
private void restoreInstanceState(Bundle savedInstanceState) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MailboxListFragment restoreInstanceState");
|
||||
}
|
||||
mSelectedMailboxId = savedInstanceState.getLong(BUNDLE_KEY_SELECTED_MAILBOX_ID);
|
||||
mSavedListState = savedInstanceState.getParcelable(BUNDLE_LIST_STATE);
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MessageFileViewFragment extends MessageViewFragmentBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
protected void clearContent() {
|
||||
super.clearContent();
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ import java.util.Set;
|
|||
* TODO Finalize batch move UI. Probably the "move" button should be disabled or hidden when
|
||||
* the selection contains non-movable messages. But then how does the user know why they can't be
|
||||
* moved?
|
||||
* TODO Restoring scroll position on screen rotation is broken.
|
||||
* TODO Restoring selected messages on screen rotation is broken.
|
||||
* TODO Remove clearContent -> most probably this is the cause for the two issues above.
|
||||
*/
|
||||
public class MessageListFragment extends ListFragment
|
||||
implements OnItemClickListener, OnItemLongClickListener, MessagesAdapter.Callback,
|
||||
|
@ -101,6 +104,9 @@ public class MessageListFragment extends ListFragment
|
|||
private static final int LOADER_ID_MAILBOX_LOADER = 1;
|
||||
private static final int LOADER_ID_MESSAGES_LOADER = 2;
|
||||
|
||||
/** Argument name(s) */
|
||||
private static final String ARG_MAILBOX_ID = "mailboxId";
|
||||
|
||||
// Controller access
|
||||
private Controller mController;
|
||||
private RefreshManager mRefreshManager;
|
||||
|
@ -228,6 +234,17 @@ public class MessageListFragment extends ListFragment
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with initialization parameters.
|
||||
*/
|
||||
public static MessageListFragment newInstance(long mailboxId) {
|
||||
final MessageListFragment instance = new MessageListFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putLong(ARG_MAILBOX_ID, mailboxId);
|
||||
instance.setArguments(args);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
|
@ -272,8 +289,11 @@ public class MessageListFragment extends ListFragment
|
|||
|
||||
if (savedInstanceState != null) {
|
||||
// Fragment doesn't have this method. Call it manually.
|
||||
loadState(savedInstanceState);
|
||||
restoreInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
final Bundle args = getArguments();
|
||||
openMailbox(args.getLong(ARG_MAILBOX_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -339,7 +359,10 @@ public class MessageListFragment extends ListFragment
|
|||
}
|
||||
|
||||
// Unit tests use it
|
||||
/* package */void loadState(Bundle savedInstanceState) {
|
||||
/* package */void restoreInstanceState(Bundle savedInstanceState) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListFragment restoreInstanceState");
|
||||
}
|
||||
mListAdapter.loadState(savedInstanceState);
|
||||
mSavedListState = savedInstanceState.getParcelable(BUNDLE_LIST_STATE);
|
||||
mSelectedMessageId = savedInstanceState.getLong(BUNDLE_KEY_SELECTED_MESSAGE_ID);
|
||||
|
@ -381,7 +404,7 @@ public class MessageListFragment extends ListFragment
|
|||
/**
|
||||
* Clear all the content, stop the loaders, etc -- should be called when the fragment is hidden.
|
||||
*/
|
||||
public void clearContent() {
|
||||
private void clearContent() {
|
||||
mMailboxId = -1;
|
||||
mLastLoadedMailboxId = -1;
|
||||
mSelectedMessageId = -1;
|
||||
|
@ -407,7 +430,8 @@ public class MessageListFragment extends ListFragment
|
|||
* @param mailboxId the ID of a mailbox, or one of "special" mailbox IDs like
|
||||
* {@link Mailbox#QUERY_ALL_INBOXES}. -1 is not allowed.
|
||||
*/
|
||||
public void openMailbox(long mailboxId) {
|
||||
// STOPSHIP Make it private once phone activities are gone
|
||||
void openMailbox(long mailboxId) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListFragment openMailbox");
|
||||
}
|
||||
|
@ -1194,7 +1218,6 @@ public class MessageListFragment extends ListFragment
|
|||
|
||||
// Various post processing...
|
||||
autoRefreshStaleMailbox();
|
||||
addFooterView();
|
||||
updateSelectionMode();
|
||||
showSendCommandIfNecessary();
|
||||
showNoMessageTextIfNecessary();
|
||||
|
|
|
@ -38,6 +38,7 @@ import android.app.ActionBar;
|
|||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.app.SearchManager;
|
||||
import android.content.ContentResolver;
|
||||
|
@ -64,6 +65,8 @@ import java.security.InvalidParameterException;
|
|||
* The main activity for multi-pane UIs. The <code>MessageListXL</code> class is responsible
|
||||
* for managing the "chrome" area of the screen; which primarily includes the action bar.
|
||||
* The rest of the content area is managed by a fragment manager.
|
||||
*
|
||||
* TODO: Fixit: Current account resets to default on screen rotation.
|
||||
*/
|
||||
public class MessageListXL extends Activity implements MessageListXLFragmentManager.TargetActivity,
|
||||
View.OnClickListener {
|
||||
|
@ -174,7 +177,7 @@ public class MessageListXL extends Activity implements MessageListXLFragmentMana
|
|||
mAccountsSelectorAdapter = new AccountSelectorAdapter(this, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
mFragmentManager.loadState(savedInstanceState);
|
||||
mFragmentManager.restoreInstanceState(savedInstanceState);
|
||||
} else {
|
||||
initFromIntent();
|
||||
}
|
||||
|
@ -213,6 +216,8 @@ public class MessageListXL extends Activity implements MessageListXLFragmentMana
|
|||
mControllerResult = new ControllerResultUiThreadWrapper<ControllerResult>(new Handler(),
|
||||
new ControllerResult());
|
||||
mController.addResultCallback(mControllerResult);
|
||||
|
||||
mFragmentManager.onActivityCreated();
|
||||
}
|
||||
|
||||
private void initFromIntent() {
|
||||
|
@ -238,6 +243,15 @@ public class MessageListXL extends Activity implements MessageListXLFragmentMana
|
|||
mFragmentManager.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachFragment(Fragment fragment) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListXL onAttachFragment fragment=" + fragment);
|
||||
}
|
||||
super.onAttachFragment(fragment);
|
||||
mFragmentManager.onAttachFragment(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Logging.LOG_TAG, "MessageListXL onStart");
|
||||
|
|
|
@ -25,18 +25,24 @@ import com.android.emailcommon.provider.EmailContent.Mailbox;
|
|||
|
||||
import android.app.ActionBar;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import java.security.InvalidParameterException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A class manages what are showing on {@link MessageListXL} (i.e. account id, mailbox id, and
|
||||
* message id), and show/hide fragments accordingly.
|
||||
*
|
||||
* Note: Always use {@link #commitFragmentTransaction} to commit fragment transactions. Currently
|
||||
* we use synchronous transactions only, but we may want to switch back to asynchronous later.
|
||||
*
|
||||
* TODO: Test it. It's testable if we implement MockFragmentTransaction, which may be too early
|
||||
* to do so at this point. (API may not be stable enough yet.)
|
||||
*
|
||||
|
@ -52,8 +58,6 @@ class MessageListXLFragmentManager implements
|
|||
private static final String BUNDLE_KEY_ACCOUNT_ID = "MessageListXl.state.account_id";
|
||||
private static final String BUNDLE_KEY_MAILBOX_ID = "MessageListXl.state.mailbox_id";
|
||||
private static final String BUNDLE_KEY_MESSAGE_ID = "MessageListXl.state.message_id";
|
||||
private static final String BUNDLE_KEY_MESSAGE_LIST_STATE
|
||||
= "MessageListXl.state.message_list_state";
|
||||
|
||||
/** No account selected */
|
||||
static final long NO_ACCOUNT = -1;
|
||||
|
@ -61,9 +65,6 @@ class MessageListXLFragmentManager implements
|
|||
static final long NO_MAILBOX = -1;
|
||||
/** No message selected */
|
||||
static final long NO_MESSAGE = -1;
|
||||
|
||||
private boolean mIsActivityResumed;
|
||||
|
||||
/** Current account id */
|
||||
private long mAccountId = NO_ACCOUNT;
|
||||
|
||||
|
@ -75,20 +76,37 @@ class MessageListXLFragmentManager implements
|
|||
|
||||
private ThreePaneLayout mThreePane;
|
||||
|
||||
/**
|
||||
* Fragments that are installed.
|
||||
*
|
||||
* A fragment is installed when:
|
||||
* - it is attached to the activity
|
||||
* - the parent activity is created
|
||||
* - and it is not scheduled to be removed.
|
||||
*
|
||||
* We set callbacks to fragments only when they are installed.
|
||||
*/
|
||||
private MailboxListFragment mMailboxListFragment;
|
||||
private MessageListFragment mMessageListFragment;
|
||||
private MessageViewFragment mMessageViewFragment;
|
||||
|
||||
private MessageCommandButtonView mMessageCommandButtons;
|
||||
|
||||
private MailboxFinder mMailboxFinder;
|
||||
|
||||
/** Save state for the "message list -> message view -[back press]-> message list" transition */
|
||||
private MessageListFragment.State mMessageListFragmentState;
|
||||
|
||||
private MessageOrderManager mOrderManager;
|
||||
private final MessageOrderManagerCallback mMessageOrderManagerCallback =
|
||||
new MessageOrderManagerCallback();
|
||||
|
||||
/**
|
||||
* List of fragments that are restored by the framework while the activity is being re-created
|
||||
* for configuration changes (e.g. screen rotation). We'll install them later when the activity
|
||||
* is created.
|
||||
*/
|
||||
private final ArrayList<Fragment> mRestoredFragments = new ArrayList<Fragment>();
|
||||
|
||||
private boolean mActivityCreated = false;
|
||||
|
||||
/**
|
||||
* The interface that {@link MessageListXL} implements. We don't call its methods directly,
|
||||
* in the hope that it'll make writing tests easier, and make it clear which methods are needed
|
||||
|
@ -176,10 +194,15 @@ class MessageListXLFragmentManager implements
|
|||
((previousVisiblePanes & ThreePaneLayout.PANE_RIGHT) != 0)) {
|
||||
// Message view just got hidden
|
||||
mMessageId = NO_MESSAGE;
|
||||
mMessageListFragment.setSelectedMessage(NO_MESSAGE);
|
||||
mMessageViewFragment.clearContent();
|
||||
if (mMessageListFragment != null) {
|
||||
mMessageListFragment.setSelectedMessage(NO_MESSAGE);
|
||||
}
|
||||
uninstallMessageViewFragment(mActivity.getFragmentManager().beginTransaction())
|
||||
.commit();
|
||||
}
|
||||
if (mMessageListFragment != null) {
|
||||
mMessageListFragment.setVisibility((visiblePanes & ThreePaneLayout.PANE_MIDDLE) != 0);
|
||||
}
|
||||
mMessageListFragment.setVisibility((visiblePanes & ThreePaneLayout.PANE_MIDDLE) != 0);
|
||||
}
|
||||
|
||||
// MailboxListFragment$Callback
|
||||
|
@ -342,28 +365,17 @@ class MessageListXLFragmentManager implements
|
|||
* Must be called just after the activity sets up the content view.
|
||||
*
|
||||
* (Due to the complexity regarding class/activity initialization order, we can't do this in
|
||||
* the constructor.)
|
||||
* the constructor.) TODO this should no longer be true when we merge activities.
|
||||
*/
|
||||
public void onActivityViewReady() {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListXLFragmentManager.onActivityViewReady");
|
||||
Log.d(Logging.LOG_TAG, "MessageListXLFragmentManager onActivityViewReady");
|
||||
}
|
||||
mThreePane = (ThreePaneLayout) mActivity.findViewById(R.id.three_pane);
|
||||
mThreePane.setCallback(this);
|
||||
|
||||
FragmentManager fm = mActivity.getFragmentManager();
|
||||
mMailboxListFragment = (MailboxListFragment) fm.findFragmentById(
|
||||
mThreePane.getLeftPaneId());
|
||||
mMessageListFragment = (MessageListFragment) fm.findFragmentById(
|
||||
mThreePane.getMiddlePaneId());
|
||||
mMessageViewFragment = (MessageViewFragment) fm.findFragmentById(
|
||||
mThreePane.getRightPaneId());
|
||||
mMessageCommandButtons = mThreePane.getMessageCommandButtons();
|
||||
mMessageCommandButtons.setCallback(new CommandButtonCallback());
|
||||
|
||||
mMailboxListFragment.setCallback(this);
|
||||
mMessageListFragment.setCallback(this);
|
||||
mMessageViewFragment.setCallback(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -408,6 +420,35 @@ class MessageListXLFragmentManager implements
|
|||
return getMessageId() != NO_MESSAGE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the end of {@link MessageListXL#onCreate}.
|
||||
*/
|
||||
public void onActivityCreated() {
|
||||
mActivityCreated = true;
|
||||
|
||||
// Install all the fragments restored by the framework.
|
||||
for (Fragment fragment : mRestoredFragments) {
|
||||
installFragment(fragment);
|
||||
}
|
||||
mRestoredFragments.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by {@link MessageListXL} when a {@link Fragment} is attached.
|
||||
*
|
||||
* If the activity has already been created, we initialize the fragment here. Otherwise we
|
||||
* keep the fragment in {@link #mRestoredFragments} and initialize it after the activity's
|
||||
* onCreate.
|
||||
*/
|
||||
public void onAttachFragment(Fragment fragment) {
|
||||
if (!mActivityCreated) {
|
||||
// Fragment being restored by the framework during the activity recreation.
|
||||
mRestoredFragments.add(fragment);
|
||||
return;
|
||||
}
|
||||
installFragment(fragment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from {@link MessageListXL#onStart}.
|
||||
*/
|
||||
|
@ -423,22 +464,12 @@ class MessageListXLFragmentManager implements
|
|||
public void onResume() {
|
||||
int visiblePanes = mThreePane.getVisiblePanes();
|
||||
mActivity.onVisiblePanesChanged(visiblePanes);
|
||||
|
||||
if (mIsActivityResumed) {
|
||||
return;
|
||||
}
|
||||
mIsActivityResumed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from {@link MessageListXL#onPause}.
|
||||
*/
|
||||
public void onPause() {
|
||||
if (!mIsActivityResumed) {
|
||||
return;
|
||||
}
|
||||
mIsActivityResumed = false;
|
||||
mMessageListFragmentState = mMessageListFragment.getState();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -452,30 +483,75 @@ class MessageListXLFragmentManager implements
|
|||
* Called from {@link MessageListXL#onDestroy}.
|
||||
*/
|
||||
public void onDestroy() {
|
||||
mActivityCreated = false;
|
||||
closeMailboxFinder();
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListXLFragmentManager onSaveInstanceState");
|
||||
}
|
||||
outState.putLong(BUNDLE_KEY_ACCOUNT_ID, mAccountId);
|
||||
outState.putLong(BUNDLE_KEY_MAILBOX_ID, mMailboxId);
|
||||
outState.putLong(BUNDLE_KEY_MESSAGE_ID, mMessageId);
|
||||
outState.putParcelable(BUNDLE_KEY_MESSAGE_LIST_STATE, mMessageListFragmentState);
|
||||
|
||||
// STOPSHIP If MailboxFinder is still running, it needs restarting after loadState().
|
||||
}
|
||||
|
||||
public void loadState(Bundle savedInstanceState) {
|
||||
long accountId = savedInstanceState.getLong(BUNDLE_KEY_ACCOUNT_ID, NO_ACCOUNT);
|
||||
long mailboxId = savedInstanceState.getLong(BUNDLE_KEY_MAILBOX_ID, NO_MAILBOX);
|
||||
long messageId = savedInstanceState.getLong(BUNDLE_KEY_MESSAGE_ID, NO_MESSAGE);
|
||||
mMessageListFragmentState = savedInstanceState.getParcelable(BUNDLE_KEY_MESSAGE_LIST_STATE);
|
||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageListXLFragmentManager: Restoring "
|
||||
+ accountId + "," + mailboxId + "," + messageId);
|
||||
Log.d(Logging.LOG_TAG, "MessageListXLFragmentManager restoreInstanceState");
|
||||
}
|
||||
if (accountId == NO_ACCOUNT) {
|
||||
return;
|
||||
mAccountId = savedInstanceState.getLong(BUNDLE_KEY_ACCOUNT_ID, NO_ACCOUNT);
|
||||
mMailboxId = savedInstanceState.getLong(BUNDLE_KEY_MAILBOX_ID, NO_MAILBOX);
|
||||
mMessageId = savedInstanceState.getLong(BUNDLE_KEY_MESSAGE_ID, NO_MESSAGE);
|
||||
}
|
||||
|
||||
private void installFragment(Fragment fragment) {
|
||||
if (fragment instanceof MailboxListFragment) {
|
||||
mMailboxListFragment = (MailboxListFragment) fragment;
|
||||
mMailboxListFragment.setCallback(this);
|
||||
} else if (fragment instanceof MessageListFragment) {
|
||||
mMessageListFragment = (MessageListFragment) fragment;
|
||||
mMessageListFragment.setCallback(this);
|
||||
} else if (fragment instanceof MessageViewFragment) {
|
||||
mMessageViewFragment = (MessageViewFragment) fragment;
|
||||
mMessageViewFragment.setCallback(this);
|
||||
} else {
|
||||
// Ignore -- uninteresting fragments such as dialogs.
|
||||
}
|
||||
// selectAccount() calls selectMailbox/Message() if necessary.
|
||||
selectAccount(accountId, mailboxId, messageId);
|
||||
}
|
||||
|
||||
private FragmentTransaction uninstallMailboxListFragment(FragmentTransaction ft) {
|
||||
if (mMailboxListFragment != null) {
|
||||
ft.remove(mMailboxListFragment);
|
||||
mMailboxListFragment.setCallback(null);
|
||||
mMailboxListFragment = null;
|
||||
}
|
||||
return ft;
|
||||
}
|
||||
|
||||
private FragmentTransaction uninstallMessageListFragment(FragmentTransaction ft) {
|
||||
if (mMessageListFragment != null) {
|
||||
ft.remove(mMessageListFragment);
|
||||
mMessageListFragment.setCallback(null);
|
||||
mMessageListFragment = null;
|
||||
}
|
||||
return ft;
|
||||
}
|
||||
|
||||
private FragmentTransaction uninstallMessageViewFragment(FragmentTransaction ft) {
|
||||
if (mMessageViewFragment != null) {
|
||||
ft.remove(mMessageViewFragment);
|
||||
mMessageViewFragment.setCallback(null);
|
||||
mMessageViewFragment = null;
|
||||
}
|
||||
return ft;
|
||||
}
|
||||
|
||||
private void commitFragmentTransaction(FragmentTransaction ft) {
|
||||
ft.commit();
|
||||
mActivity.getFragmentManager().executePendingTransactions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -515,12 +591,16 @@ class MessageListXLFragmentManager implements
|
|||
mMailboxId = NO_MAILBOX;
|
||||
mMessageId = NO_MESSAGE;
|
||||
|
||||
// In case of "message list -> message view -> change account", we don't have to keep it.
|
||||
mMessageListFragmentState = null;
|
||||
// Open mailbox list, remove message list / message view
|
||||
final FragmentManager fm = mActivity.getFragmentManager();
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
uninstallMailboxListFragment(ft);
|
||||
uninstallMessageListFragment(ft);
|
||||
uninstallMessageViewFragment(ft);
|
||||
ft.add(mThreePane.getLeftPaneId(),
|
||||
MailboxListFragment.newInstance(getUIAccountId(), forceReload));
|
||||
commitFragmentTransaction(ft);
|
||||
|
||||
// Open mailbox list, clear message list / message view
|
||||
mMailboxListFragment.openMailboxes(mAccountId, forceReload);
|
||||
mMessageListFragment.clearContent();
|
||||
mThreePane.showLeftPane(); // Show mailbox list
|
||||
|
||||
if ((accountId == Account.ACCOUNT_ID_COMBINED_VIEW) && (mailboxId == NO_MAILBOX)) {
|
||||
|
@ -582,11 +662,14 @@ class MessageListXLFragmentManager implements
|
|||
}
|
||||
mMailboxId = mailboxId;
|
||||
mMessageId = NO_MESSAGE;
|
||||
if (mMessageListFragmentState != null) {
|
||||
mMessageListFragmentState.restore(mMessageListFragment);
|
||||
mMessageListFragmentState = null;
|
||||
}
|
||||
mMessageListFragment.openMailbox(mailboxId);
|
||||
|
||||
final FragmentManager fm = mActivity.getFragmentManager();
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
uninstallMessageListFragment(ft);
|
||||
uninstallMessageViewFragment(ft);
|
||||
ft.add(mThreePane.getMiddlePaneId(), MessageListFragment.newInstance(mailboxId));
|
||||
commitFragmentTransaction(ft);
|
||||
|
||||
if (navigateToMailbox) {
|
||||
mMailboxListFragment.navigateToMailbox(mailboxId);
|
||||
} else {
|
||||
|
@ -618,14 +701,18 @@ class MessageListXLFragmentManager implements
|
|||
return;
|
||||
}
|
||||
|
||||
mMessageListFragmentState = mMessageListFragment.getState();
|
||||
|
||||
// Update member
|
||||
mMessageId = messageId;
|
||||
|
||||
// Open message
|
||||
mMessageListFragment.setSelectedMessage(mMessageId);
|
||||
mMessageViewFragment.openMessage(mMessageId);
|
||||
|
||||
final FragmentManager fm = mActivity.getFragmentManager();
|
||||
final FragmentTransaction ft = fm.beginTransaction();
|
||||
uninstallMessageViewFragment(ft);
|
||||
ft.add(mThreePane.getRightPaneId(), MessageViewFragment.newInstance(messageId));
|
||||
commitFragmentTransaction(ft);
|
||||
|
||||
mThreePane.showRightPane(); // Show message view
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,9 @@ import java.security.InvalidParameterException;
|
|||
*/
|
||||
public class MessageViewFragment extends MessageViewFragmentBase
|
||||
implements CheckBox.OnCheckedChangeListener {
|
||||
/** Argument name(s) */
|
||||
private static final String ARG_MESSAGE_ID = "messageId";
|
||||
|
||||
private ImageView mFavoriteIcon;
|
||||
private View mInviteSection;
|
||||
|
||||
|
@ -136,6 +139,17 @@ public class MessageViewFragment extends MessageViewFragmentBase
|
|||
|
||||
private Callback mCallback = EmptyCallback.INSTANCE;
|
||||
|
||||
/**
|
||||
* Create a new instance with initialization parameters.
|
||||
*/
|
||||
public static MessageViewFragment newInstance(long messageId) {
|
||||
final MessageViewFragment instance = new MessageViewFragment();
|
||||
final Bundle args = new Bundle();
|
||||
args.putLong(ARG_MESSAGE_ID, messageId);
|
||||
instance.setArguments(args);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -176,6 +190,14 @@ public class MessageViewFragment extends MessageViewFragmentBase
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
final Bundle args = getArguments();
|
||||
openMessage(args.getLong(ARG_MESSAGE_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -200,7 +222,8 @@ public class MessageViewFragment extends MessageViewFragmentBase
|
|||
}
|
||||
|
||||
/** Called by activities to set an id of a message to open. */
|
||||
public void openMessage(long messageId) {
|
||||
// STOPSHIP Make it private once phone activities are gone
|
||||
void openMessage(long messageId) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageViewFragment openMessage");
|
||||
}
|
||||
|
@ -214,7 +237,7 @@ public class MessageViewFragment extends MessageViewFragmentBase
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clearContent() {
|
||||
protected void clearContent() {
|
||||
synchronized (mLock) {
|
||||
super.clearContent();
|
||||
mMessageIdToOpen = -1;
|
||||
|
|
|
@ -406,6 +406,9 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||
}
|
||||
|
||||
private void restoreInstanceState(Bundle state) {
|
||||
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) {
|
||||
Log.d(Logging.LOG_TAG, "MessageViewFragment restoreInstanceState");
|
||||
}
|
||||
// At this point (in onCreate) no tabs are visible (because we don't know if the message has
|
||||
// an attachment or invite before loading it). We just remember the tab here.
|
||||
// We'll make it current when the tab first becomes visible in updateTabs().
|
||||
|
@ -454,7 +457,7 @@ public abstract class MessageViewFragmentBase extends Fragment implements View.O
|
|||
/**
|
||||
* Clear all the content -- should be called when the fragment is hidden.
|
||||
*/
|
||||
public void clearContent() {
|
||||
protected void clearContent() {
|
||||
cancelAllTasks();
|
||||
resetView();
|
||||
}
|
||||
|
|
|
@ -100,9 +100,9 @@ public class ThreePaneLayout extends LinearLayout implements View.OnClickListene
|
|||
private AnimatorListener mLastAnimatorListener;
|
||||
|
||||
// 2nd index for {@link #changePaneState}
|
||||
private final int INDEX_VISIBLE = 0;
|
||||
private final int INDEX_INVISIBLE = 1;
|
||||
private final int INDEX_GONE = 2;
|
||||
private static final int INDEX_VISIBLE = 0;
|
||||
private static final int INDEX_INVISIBLE = 1;
|
||||
private static final int INDEX_GONE = 2;
|
||||
|
||||
// Arrays used in {@link #changePaneState}
|
||||
// First index: STATE_*
|
||||
|
|
Loading…
Reference in New Issue