Highlight selected message on message list
Also make sure the highlighted mailbox is always visible on the mailbox list. MessageListFragment now just uses the default background color, which means it no longer changes background color for unread messages or checked messages. This should be re-implemented if necessary with the newer wireframe. Change-Id: I9bfbe9f0711ea4ab56be27778b00298d3033123b
This commit is contained in:
parent
793c6639ec
commit
58843f0dc3
|
@ -18,7 +18,9 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:paddingRight="10dip">
|
||||
android:paddingRight="10dip"
|
||||
android:background="?android:attr/activatedBackgroundIndicator"
|
||||
>
|
||||
<View
|
||||
android:id="@+id/chip"
|
||||
android:background="@drawable/appointment_indicator_leftside_1"
|
||||
|
|
|
@ -305,6 +305,7 @@ public class MailboxListFragment extends ListFragment implements OnItemClickList
|
|||
for (int i = 0; i < count; i++) {
|
||||
if (mListView.getItemIdAtPosition(i) == mSelectedMailboxId) {
|
||||
mListView.setItemChecked(i, true);
|
||||
mListView.smoothScrollToPosition(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ public class MessageListFragment extends ListFragment
|
|||
implements OnItemClickListener, OnItemLongClickListener, MessagesAdapter.Callback,
|
||||
OnClickListener, MoveMessageToDialog.Callback {
|
||||
private static final String BUNDLE_LIST_STATE = "MessageListFragment.state.listState";
|
||||
private static final String BUNDLE_KEY_SELECTED_MESSAGE_ID
|
||||
= "messageListFragment.state.listState.selected_message_id";
|
||||
|
||||
private static final int LOADER_ID_MAILBOX_LOADER = 1;
|
||||
private static final int LOADER_ID_MESSAGES_LOADER = 2;
|
||||
|
@ -87,6 +89,7 @@ public class MessageListFragment extends ListFragment
|
|||
private Activity mActivity;
|
||||
private Callback mCallback = EmptyCallback.INSTANCE;
|
||||
|
||||
private ListView mListView;
|
||||
private View mListFooterView;
|
||||
private TextView mListFooterText;
|
||||
private View mListFooterProgress;
|
||||
|
@ -100,6 +103,8 @@ public class MessageListFragment extends ListFragment
|
|||
|
||||
private long mMailboxId = -1;
|
||||
private long mLastLoadedMailboxId = -1;
|
||||
private long mSelectedMessageId = -1;
|
||||
|
||||
private Account mAccount;
|
||||
private Mailbox mMailbox;
|
||||
private boolean mIsEasAccount;
|
||||
|
@ -197,15 +202,16 @@ public class MessageListFragment extends ListFragment
|
|||
}
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
ListView listView = getListView();
|
||||
listView.setOnItemClickListener(this);
|
||||
listView.setOnItemLongClickListener(this);
|
||||
listView.setItemsCanFocus(false);
|
||||
mListView = getListView();
|
||||
mListView.setOnItemClickListener(this);
|
||||
mListView.setOnItemLongClickListener(this);
|
||||
mListView.setItemsCanFocus(false);
|
||||
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
|
||||
mListAdapter = new MessagesAdapter(mActivity, this);
|
||||
|
||||
mListFooterView = getActivity().getLayoutInflater().inflate(
|
||||
R.layout.message_list_item_footer, listView, false);
|
||||
R.layout.message_list_item_footer, mListView, false);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
// Fragment doesn't have this method. Call it manually.
|
||||
|
@ -273,12 +279,14 @@ public class MessageListFragment extends ListFragment
|
|||
super.onSaveInstanceState(outState);
|
||||
mListAdapter.onSaveInstanceState(outState);
|
||||
outState.putParcelable(BUNDLE_LIST_STATE, new Utility.ListStateSaver(getListView()));
|
||||
outState.putLong(BUNDLE_KEY_SELECTED_MESSAGE_ID, mSelectedMessageId);
|
||||
}
|
||||
|
||||
// Unit tests use it
|
||||
/* package */void loadState(Bundle savedInstanceState) {
|
||||
mListAdapter.loadState(savedInstanceState);
|
||||
mSavedListState = savedInstanceState.getParcelable(BUNDLE_LIST_STATE);
|
||||
mSelectedMessageId = savedInstanceState.getLong(BUNDLE_KEY_SELECTED_MESSAGE_ID);
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
|
@ -311,6 +319,13 @@ public class MessageListFragment extends ListFragment
|
|||
}
|
||||
}
|
||||
|
||||
public void setSelectedMessage(long messageId) {
|
||||
mSelectedMessageId = messageId;
|
||||
if (mResumed) {
|
||||
highlightSelectedMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/* package */MessagesAdapter getAdapterForTest() {
|
||||
return mListAdapter;
|
||||
}
|
||||
|
@ -920,6 +935,7 @@ public class MessageListFragment extends ListFragment
|
|||
addFooterView();
|
||||
updateSelectionMode();
|
||||
showSendPanelIfNecessary();
|
||||
highlightSelectedMessage();
|
||||
|
||||
// Restore the state -- it has to be the last.
|
||||
// (Some of the "post processing" resets the state.)
|
||||
|
@ -1098,4 +1114,24 @@ public class MessageListFragment extends ListFragment
|
|||
public State getState() {
|
||||
return new State(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Highlight the selected message.
|
||||
*/
|
||||
private void highlightSelectedMessage() {
|
||||
if (mSelectedMessageId == -1) {
|
||||
// No mailbox selected
|
||||
mListView.clearChoices();
|
||||
return;
|
||||
}
|
||||
|
||||
final int count = mListView.getCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (mListView.getItemIdAtPosition(i) == mSelectedMessageId) {
|
||||
mListView.setItemChecked(i, true);
|
||||
mListView.smoothScrollToPosition(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,6 +417,7 @@ class MessageListXLFragmentManager {
|
|||
if (mMailboxListFragment != null) {
|
||||
mMailboxListFragment.setSelectedMailbox(mMailboxId);
|
||||
}
|
||||
hideMessageView();
|
||||
}
|
||||
|
||||
private void updateMessageListFragment(MessageListFragment fragment) {
|
||||
|
@ -481,6 +482,7 @@ class MessageListXLFragmentManager {
|
|||
if (mAccountId == -1 || mMailboxId == -1 || mMessageId == -1) { // Shouldn't happen
|
||||
throw new RuntimeException();
|
||||
}
|
||||
mMessageListFragment.setSelectedMessage(mMessageId);
|
||||
mMessageViewFragment = fragment;
|
||||
fragment.setCallback(mMessageViewFragmentCallback);
|
||||
fragment.openMessage(mMessageId);
|
||||
|
@ -500,6 +502,9 @@ class MessageListXLFragmentManager {
|
|||
mFragmentManager.openTransaction().remove(mMessageViewFragment).commit();
|
||||
mMessageViewFragment = null;
|
||||
}
|
||||
if (mMessageListFragment != null) {
|
||||
mMessageListFragment.setSelectedMessage(-1);
|
||||
}
|
||||
}
|
||||
|
||||
private void startInboxLookup() {
|
||||
|
|
|
@ -223,14 +223,10 @@ import java.util.Set;
|
|||
subjectView.setTypeface(Typeface.DEFAULT);
|
||||
fromView.setTypeface(Typeface.DEFAULT);
|
||||
fromView.setTextColor(mTextColorSecondary);
|
||||
view.setBackgroundDrawable(context.getResources().getDrawable(
|
||||
R.drawable.message_list_item_background_read));
|
||||
} else {
|
||||
subjectView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
fromView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
fromView.setTextColor(mTextColorPrimary);
|
||||
view.setBackgroundDrawable(context.getResources().getDrawable(
|
||||
R.drawable.message_list_item_background_unread));
|
||||
}
|
||||
|
||||
updateCheckBox(itemView);
|
||||
|
@ -294,11 +290,7 @@ import java.util.Set;
|
|||
* Update the background color according to the selection state.
|
||||
*/
|
||||
public void updateBackgroundColor(MessageListItem itemView) {
|
||||
if (isSelected(itemView)) {
|
||||
itemView.setBackgroundColor(ITEM_BACKGROUND_SELECTED);
|
||||
} else {
|
||||
itemView.setBackgroundDrawable(null); // Change back to default.
|
||||
}
|
||||
// TODO Visual for selected items is not decided.
|
||||
}
|
||||
|
||||
public static Loader<Cursor> createLoader(Context context, long mailboxId) {
|
||||
|
|
Loading…
Reference in New Issue