summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/ui/ConversationListFragment.java
diff options
context:
space:
mode:
authorJin Cao <jinyan@google.com>2014-10-17 13:42:10 -0700
committerJin Cao <jinyan@google.com>2014-10-17 16:19:37 -0700
commitf9b96e244e6c6a19cb1920ff129f424997db2727 (patch)
treede7b0c1e45a7051ec8d07bd94217bde2fff7c99c /src/com/android/mail/ui/ConversationListFragment.java
parent17553ce2afdf3f8be5e53a639ac8f2593e388fec (diff)
downloadandroid_packages_apps_UnifiedEmail-f9b96e244e6c6a19cb1920ff129f424997db2727.tar.gz
android_packages_apps_UnifiedEmail-f9b96e244e6c6a19cb1920ff129f424997db2727.tar.bz2
android_packages_apps_UnifiedEmail-f9b96e244e6c6a19cb1920ff129f424997db2727.zip
Save the focused conversation via id instead of position
Don't rely on saving the position in the adapter because the position might change as the adapter's data set changes (e.g. new mails via sync), and we have no way of modifying the focused position accordingly. Instead, save the focused conversation with its id (tried using the uri, but the uri might change when the conversation gets cached). This way, no matter what happens to the items in the adapter, the focused item remains consistent. b/18027602 Change-Id: I51aa68bc15c5892c3b34bde5c199de281390ce7b
Diffstat (limited to 'src/com/android/mail/ui/ConversationListFragment.java')
-rw-r--r--src/com/android/mail/ui/ConversationListFragment.java30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index d80cdf9ad..439f6b597 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -493,7 +493,7 @@ public final class ConversationListFragment extends Fragment implements
sb.append(mViewContext.folder);
if (mListView != null) {
sb.append(" selectedPos=");
- sb.append(mListView.getSelectedPosition());
+ sb.append(mListView.getSelectedConversationPosDebug());
sb.append(" listSelectedPos=");
sb.append(mListView.getSelectedItemPosition());
sb.append(" isListInTouchMode=");
@@ -858,7 +858,7 @@ public final class ConversationListFragment extends Fragment implements
* special views in the list.
*/
conv.position = cursor.getPosition();
- setActivated(conv.position, true);
+ setActivated(conv, true);
mCallbacks.onConversationSelected(conv, false /* inLoaderCallbacks */);
} else {
LogUtils.e(LOG_TAG,
@@ -869,41 +869,41 @@ public final class ConversationListFragment extends Fragment implements
/**
* Sets the checked conversation to the position given here.
- * @param cursorPosition The position of the conversation in the cursor (as opposed to
- * in the list)
+ * @param conversation the activated conversation.
* @param different if the currently checked conversation is different from the one provided
* here. This is a difference in conversations, not a difference in positions. For example, a
* conversation at position 2 can move to position 4 as a result of new mail.
*/
- public void setActivated(final int cursorPosition, boolean different) {
- if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
+ public void setActivated(final Conversation conversation, boolean different) {
+ if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE || conversation == null) {
return;
}
+ final int cursorPosition = conversation.position;
final int position = cursorPosition + mListAdapter.getPositionOffset(cursorPosition);
setRawActivated(position, different);
- setRawSelected(position);
+ setRawSelected(conversation, position);
}
/**
* Set the selected conversation (used by the framework to indicate current focus in the list).
- * @param cursorPosition The position of the conversation in the cursor (as opposed to
- * in the list)
+ * @param conversation the selected conversation.
*/
- public void setSelected(final int cursorPosition) {
- if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
+ public void setSelected(final Conversation conversation) {
+ if (mListView.getChoiceMode() == ListView.CHOICE_MODE_NONE || conversation == null) {
return;
}
+ final int cursorPosition = conversation.position;
final int position = cursorPosition + mListAdapter.getPositionOffset(cursorPosition);
- setRawSelected(position);
+ setRawSelected(conversation, position);
}
/**
* Set the selected conversation (used by the framework to indicate current focus in the list).
* @param position The position of the item in the list
*/
- private void setRawSelected(final int position) {
+ private void setRawSelected(Conversation conversation, final int position) {
final View selectedView = mListView.getChildAt(
position - mListView.getFirstVisiblePosition());
// Don't do anything if the view is already selected.
@@ -919,7 +919,7 @@ public final class ConversationListFragment extends Fragment implements
// setSelection calls setSelectionFromTop with y = 0.
mListView.setSelectionFromTop(position, selectedView.getTop());
}
- mListView.setSelectedPosition(position);
+ mListView.setSelectedConversation(conversation);
}
}
@@ -1154,7 +1154,7 @@ public final class ConversationListFragment extends Fragment implements
if (conv != null && !currentConvIsPeeking) {
if (mListView.getChoiceMode() != ListView.CHOICE_MODE_NONE
&& mListView.getCheckedItemPosition() == -1) {
- setActivated(conv.position, true);
+ setActivated(conv, true);
}
}
}