Clear selection set when viewing messages on one-pane
This is missing one crucial functionality:
In conversation view, if we perform destructive actions on the selected conversations, the
selected set is not accurately updated.
For a correct implementation, we need a ConversationPositionTracker class, so that will be solved
in a second pass.
Change-Id: Ie9909ce026c4ec1148b4817d6968699b392e2330
diff --git a/src/com/android/mail/browse/SelectedConversationsActionMenu.java b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
index 558972d..0db79d0 100644
--- a/src/com/android/mail/browse/SelectedConversationsActionMenu.java
+++ b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
@@ -99,10 +99,13 @@
private Folder mFolder;
- private ActionCompleteListener mDeleteListener = new DestructiveActionListener(R.id.delete);
- private ActionCompleteListener mArchiveListener = new DestructiveActionListener(R.id.archive);
- private ActionCompleteListener mMuteListener = new DestructiveActionListener(R.id.mute);
- private ActionCompleteListener mSpamListener = new DestructiveActionListener(R.id.report_spam);
+ private final ActionCompleteListener mDeleteListener =
+ new DestructiveActionListener(R.id.delete);
+ private final ActionCompleteListener mArchiveListener =
+ new DestructiveActionListener(R.id.archive);
+ private final ActionCompleteListener mMuteListener = new DestructiveActionListener(R.id.mute);
+ private final ActionCompleteListener mSpamListener =
+ new DestructiveActionListener(R.id.report_spam);
public SelectedConversationsActionMenu(RestrictedActivity activity,
ConversationSelectionSet selectionSet, AnimatedAdapter adapter,
@@ -253,7 +256,7 @@
}
}
- private ActionCompleteListener mFolderChangeListener = new ActionCompleteListener() {
+ private final ActionCompleteListener mFolderChangeListener = new ActionCompleteListener() {
@Override
public void onActionComplete() {
mActionCompleteListener.onActionComplete();
@@ -393,9 +396,14 @@
}
/**
- * Activates and shows this menu (essentially starting an {@link ActionMode}).
+ * Activates and shows this menu (essentially starting an {@link ActionMode}) if the selected
+ * set is non-empty.
*/
public void activate() {
+ if (mSelectionSet.isEmpty()) {
+ // We have nothing to do since there is no conversation selected.
+ return;
+ }
mActivated = true;
if (mActionMode == null) {
mActivity.startActionMode(this);
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index bb907c8..fa1bb42 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -133,6 +133,10 @@
*/
private final ConversationSelectionSet mSelectedSet = new ConversationSelectionSet();
+ /**
+ * Action menu associated with the selected set.
+ */
+ SelectedConversationsActionMenu mCabActionMenu;
protected static final String LOG_TAG = new LogUtils().getLogTag();
/** Constants used to differentiate between the types of loaders. */
@@ -887,6 +891,14 @@
setCurrentConversation(conversation);
}
+ /**
+ * Children can override this method, but they must call super.showConversationList().
+ * {@inheritDoc}
+ */
+ @Override
+ public void showConversationList(ConversationListContext listContext) {
+ }
+
@Override
public void onConversationSelected(Conversation conversation) {
showConversation(conversation);
@@ -1343,10 +1355,10 @@
@Override
public void onSetPopulated(ConversationSelectionSet set) {
- SelectedConversationsActionMenu menu = new SelectedConversationsActionMenu(mActivity,
+ mCabActionMenu = new SelectedConversationsActionMenu(mActivity,
set, mConversationListFragment.getAnimatedAdapter(), this,
mConversationListFragment, mAccount, mFolder);
- menu.activate();
+ enableCabMode();
}
@@ -1360,6 +1372,24 @@
return mSelectedSet;
}
+ /**
+ * Disable the Contextual Action Bar (CAB). The selected set is not changed.
+ */
+ protected void disableCabMode() {
+ if (mCabActionMenu != null) {
+ mCabActionMenu.deactivate();
+ }
+ }
+
+ /**
+ * Re-enable the CAB menu if required. The selection set is not changed.
+ */
+ protected void enableCabMode() {
+ if (mCabActionMenu != null) {
+ mCabActionMenu.activate();
+ }
+ }
+
@Override
public void onActionComplete() {
if (getConversationListCursor().isRefreshReady()) {
diff --git a/src/com/android/mail/ui/OnePaneController.java b/src/com/android/mail/ui/OnePaneController.java
index 5af0273..f9354d6 100644
--- a/src/com/android/mail/ui/OnePaneController.java
+++ b/src/com/android/mail/ui/OnePaneController.java
@@ -150,6 +150,8 @@
@Override
public void showConversationList(ConversationListContext listContext) {
+ super.showConversationList(listContext);
+ enableCabMode();
// TODO(viki): Check if the account has been changed since the previous
// time.
if (listContext != null && listContext.isSearchResult()) {
@@ -182,6 +184,7 @@
@Override
public void showConversation(Conversation conversation) {
super.showConversation(conversation);
+ disableCabMode();
if (mConvListContext != null && mConvListContext.isSearchResult()) {
mViewMode.enterSearchResultsConversationMode();
} else {
diff --git a/src/com/android/mail/ui/TwoPaneController.java b/src/com/android/mail/ui/TwoPaneController.java
index 66ada5d..caf32de 100644
--- a/src/com/android/mail/ui/TwoPaneController.java
+++ b/src/com/android/mail/ui/TwoPaneController.java
@@ -129,7 +129,8 @@
}
@Override
- public void showConversationList(ConversationListContext context) {
+ public void showConversationList(ConversationListContext listContext) {
+ super.showConversationList(listContext);
initializeConversationListFragment(true);
}