Show MessageList with MessageView, rather than MailboxList

In message view mode, show MessageListFragment on the left pane.

TODO: Highlight opened message on message list
TODO: If the opened message is moved/deleted/starred/etc, update
message view
TODO: Collapsible left pane on portrait

Change-Id: I9b26f7291648da0e08bc526b79305ab65ce4d926
This commit is contained in:
Makoto Onuki 2010-09-21 15:36:23 -07:00
parent 353b75b04b
commit 250ca15b88
4 changed files with 66 additions and 18 deletions

View File

@ -23,12 +23,20 @@
<FrameLayout
android:id="@+id/left_pane"
android:layout_width="360dip"
android:layout_width="300dip"
android:layout_height="match_parent"
android:layout_weight="0"
/>
<FrameLayout
android:id="@+id/middle_pane"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<FrameLayout
android:id="@+id/right_pane"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1" />
android:layout_weight="2"
/>
</LinearLayout>

View File

@ -112,6 +112,7 @@ public class MessageListXL extends Activity implements
if (Email.DEBUG_LIFECYCLE && Email.DEBUG) Log.d(Email.LOG_TAG, "MessageListXL onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.message_list_xl);
mFragmentManager.onActivityViewReady();
final boolean isRestoring = (savedInstanceState != null);

View File

@ -26,23 +26,17 @@ import android.app.FragmentTransaction;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import java.security.InvalidParameterException;
import java.util.ArrayList;
/*
TODO: When opening a mailbox I see this:
D Email : com.android.email.activity.MailboxListFragment openMailboxes
D Email : com.android.email.activity.MailboxListFragment onCreate *1 <- Why second instance???
D Email : com.android.email.activity.MailboxListFragment onActivityCreated
D Email : com.android.email.activity.MailboxListFragment onStart
D Email : com.android.email.activity.MailboxListFragment onResume
*/
/**
* A class manages what are showing on {@link MessageListXL} (i.e. account id, mailbox id, and
* message id), and show/hide fragments accordingly.
*
* TODO Highlight selected message on message list
*
* 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.)
*/
@ -72,6 +66,10 @@ class MessageListXLFragmentManager {
/** Current message id. (-1 = not selected) */
private long mMessageId = -1;
private View mLeftPane;
private View mMiddlePane;
private View mRightPane;
private MailboxListFragment mMailboxListFragment;
private MessageListFragment mMessageListFragment;
private MessageViewFragment mMessageViewFragment;
@ -105,6 +103,8 @@ class MessageListXLFragmentManager {
* Called when the current mailbox has changed.
*/
public void onMailboxChanged(long accountId, long newMailboxId);
public View findViewById(int id);
}
private final TargetActivity mTargetActivity;
@ -116,6 +116,18 @@ class MessageListXLFragmentManager {
mFragmentManager = mTargetActivity.getFragmentManager();
}
/**
* 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.)
*/
public void onActivityViewReady() {
mLeftPane = mTargetActivity.findViewById(R.id.left_pane);
mMiddlePane = mTargetActivity.findViewById(R.id.middle_pane);
mRightPane = mTargetActivity.findViewById(R.id.right_pane);
}
/** Set callback for fragment. */
public void setMailboxListFragmentCallback(
MailboxListFragment.Callback mailboxListFragmentCallback) {
@ -324,6 +336,7 @@ class MessageListXLFragmentManager {
} else {
selectMailbox(mailboxId, byExplicitUserAction);
}
hideMessageView();
}
private void updateMailboxListFragment(MailboxListFragment fragment) {
@ -339,6 +352,9 @@ class MessageListXLFragmentManager {
if (mMailboxId != -1) {
mMailboxListFragment.setSelectedMailbox(mMailboxId);
}
if (!isMessageSelected()) {
hideMessageView();
}
}
/**
@ -346,6 +362,7 @@ class MessageListXLFragmentManager {
*/
public void goBackToMailbox() {
if (isMessageSelected()) {
hideMessageView();
selectMailbox(getMailboxId(), false);
}
}
@ -367,7 +384,8 @@ class MessageListXLFragmentManager {
if (mailboxId == -1) {
throw new InvalidParameterException();
}
if ((mMailboxId == mailboxId) && !isMessageSelected()) {
if (mMailboxId == mailboxId) {
return;
}
@ -381,12 +399,15 @@ class MessageListXLFragmentManager {
if (byExplicitUserAction) {
f.doAutoRefresh();
}
mFragmentManager.openTransaction().replace(R.id.right_pane, f).commit();
FragmentTransaction ft = mFragmentManager.openTransaction()
.replace(R.id.middle_pane, f);
if (mMessageViewFragment != null) {
// Message view will disappear.
ft.remove(mMessageViewFragment);
mMessageViewFragment = null;
}
ft.commit();
} else {
if (byExplicitUserAction) {
mMessageListFragment.doAutoRefresh();
@ -411,6 +432,9 @@ class MessageListXLFragmentManager {
mMessageListFragment.openMailbox(mMailboxId);
restoreMesasgeListState();
mTargetActivity.onMailboxChanged(mAccountId, mMailboxId);
if (!isMessageSelected()) {
hideMessageView();
}
}
/**
@ -445,7 +469,6 @@ class MessageListXLFragmentManager {
mFragmentManager.openTransaction().replace(R.id.right_pane, f)
// .addToBackStack(null)
.commit();
mMessageListFragment = null;
} else {
updateMessageViewFragment(mMessageViewFragment);
}
@ -461,6 +484,22 @@ class MessageListXLFragmentManager {
mMessageViewFragment = fragment;
fragment.setCallback(mMessageViewFragmentCallback);
fragment.openMessage(mMessageId);
hideMessageBoxList();
}
private void hideMessageBoxList() {
mLeftPane.setVisibility(View.GONE);
mRightPane.setVisibility(View.VISIBLE);
}
private void hideMessageView() {
mMessageId = -1;
mRightPane.setVisibility(View.GONE);
mLeftPane.setVisibility(View.VISIBLE);
if (mMessageViewFragment != null) {
mFragmentManager.openTransaction().remove(mMessageViewFragment).commit();
mMessageViewFragment = null;
}
}
private void startInboxLookup() {

View File

@ -74,9 +74,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
// TODO Restore "Show pictures" state and scroll position on rotation.
// TODO New UI allows MessageListFragment to toggle star while MessageViewFragment is shown, which
// means this fragment needs to observe DB changes and refresh the UI.
// (But what about "mark as unread"?)
// TODO Interaction with MessageListFragment
// Messages can now be moved, deleted, starred, and makred as unread at anytime, without this
// fragment knowing it. Update (or close or whatever) the fragment as necessary.
/**
* Base class for {@link MessageViewFragment} and {@link MessageFileViewFragment}.