Remove views from selected set.

The views were originally being used in the ConversationListFragment
to delete items. They are no longer being used now, but we still
maintain extensive maps and pass the collections around.  We can stop
doing this extra work.

This does not fix any bug, but the cleanup was found while
investigating the bug below.

Bug: 7067964 Gmail: archives wrong message

Change-Id: I2b7d387fe5ab078b2006f27cc8167b354d0bb1c8
diff --git a/src/com/android/mail/browse/SelectedConversationsActionMenu.java b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
index da931be..5a6da15 100644
--- a/src/com/android/mail/browse/SelectedConversationsActionMenu.java
+++ b/src/com/android/mail/browse/SelectedConversationsActionMenu.java
@@ -127,7 +127,7 @@
                 performDestructiveAction(R.id.archive);
                 break;
             case R.id.remove_folder:
-                destroy(R.id.remove_folder, mSelectionSet.values(), mSelectionSet.views(),
+                destroy(R.id.remove_folder, mSelectionSet.values(),
                         mUpdater.getDeferredRemoveFolder(mSelectionSet.values(), mFolder, true,
                                 true, true));
                 break;
@@ -261,15 +261,14 @@
         } else {
             // No need to show the dialog, just make a destructive action and destroy the
             // selected set immediately.
-            final Collection<ConversationItemView> views = mSelectionSet.views();
             // TODO(viki): Stop using the deferred action here. Use the registered action.
-            destroy(action, conversations, views, mUpdater.getDeferredBatchAction(action));
+            destroy(action, conversations, mUpdater.getDeferredBatchAction(action));
         }
     }
 
     private void destroy(int action, final Collection<Conversation> conversations,
-            final Collection<ConversationItemView> views, final DestructiveAction listener) {
-        mUpdater.delete(action, conversations, views, listener);
+            final DestructiveAction listener) {
+        mUpdater.delete(action, conversations, listener);
     }
 
     /**
diff --git a/src/com/android/mail/ui/AbstractActivityController.java b/src/com/android/mail/ui/AbstractActivityController.java
index 1facd29..ff608e0 100644
--- a/src/com/android/mail/ui/AbstractActivityController.java
+++ b/src/com/android/mail/ui/AbstractActivityController.java
@@ -1282,13 +1282,13 @@
             final ConfirmDialogFragment c = ConfirmDialogFragment.newInstance(message);
             c.displayDialog(mActivity.getFragmentManager());
         } else {
-            delete(0, target, null, getDeferredAction(actionId, target, false));
+            delete(0, target, getDeferredAction(actionId, target, false));
         }
     }
 
     @Override
     public void delete(final int actionId, final Collection<Conversation> target,
-            final Collection<ConversationItemView> targetViews, final DestructiveAction action) {
+            final DestructiveAction action) {
         // Order of events is critical! The Conversation View Fragment must be
         // notified of the next conversation with showConversation(next) *before* the
         // conversation list
@@ -1299,7 +1299,7 @@
         final Runnable operation = new Runnable() {
             @Override
             public void run() {
-                delete(actionId, target, targetViews, action);
+                delete(actionId, target, action);
             }
         };
 
@@ -1312,7 +1312,7 @@
         final ConversationListFragment convListFragment = getConversationListFragment();
         if (convListFragment != null) {
             LogUtils.d(LOG_TAG, "AAC.requestDelete: ListFragment is handling delete.");
-            convListFragment.requestDelete(actionId, target, targetViews, action);
+            convListFragment.requestDelete(actionId, target, action);
             return;
         }
         // No visible UI element handled it on our behalf. Perform the action
@@ -1320,12 +1320,6 @@
         action.performAction();
     }
 
-    @Override
-    public void delete(int actionId, final Collection<Conversation> target,
-            final DestructiveAction action) {
-        delete(actionId, target, null, action);
-    }
-
     /**
      * Requests that the action be performed and the UI state is updated to reflect the new change.
      * @param target
@@ -2666,7 +2660,7 @@
         // dragged/ dropped conversations.
         if (convListFragment != null) {
             LogUtils.d(LOG_TAG, "AAC.requestDelete: ListFragment is handling delete.");
-            convListFragment.requestDelete(R.id.change_folder, conversations, mSelectedSet.views(),
+            convListFragment.requestDelete(R.id.change_folder, conversations,
                     new DroppedInStarredAction(conversations, mFolder, folder));
             return;
         }
@@ -3181,15 +3175,11 @@
     @Override
     public void makeDialogListener (final int action, boolean isBatch) {
         final Collection<Conversation> target;
-        final Collection<ConversationItemView> views;
         if (isBatch) {
             target = mSelectedSet.values();
-            views = mSelectedSet.views();
         } else {
             LogUtils.d(LOG_TAG, "Will act upon %s", mCurrentConversation);
             target = Conversation.listOf(mCurrentConversation);
-            // When the current conversation is deleted, we don't need to update the views.
-            views = null;
         }
         final DestructiveAction destructiveAction = getDeferredAction(action, target, isBatch);
         mDialogAction = action;
@@ -3197,7 +3187,7 @@
         mDialogListener = new AlertDialog.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int which) {
-                delete(action, target, views, destructiveAction);
+                delete(action, target, destructiveAction);
                 // Afterwards, let's remove references to the listener and the action.
                 setListener(null, -1);
             }
diff --git a/src/com/android/mail/ui/ConversationListFragment.java b/src/com/android/mail/ui/ConversationListFragment.java
index 3e3c023..12f31fa 100644
--- a/src/com/android/mail/ui/ConversationListFragment.java
+++ b/src/com/android/mail/ui/ConversationListFragment.java
@@ -56,7 +56,6 @@
 import com.android.mail.utils.LogUtils;
 import com.android.mail.utils.Utils;
 
-import java.util.ArrayList;
 import java.util.Collection;
 
 /**
@@ -557,7 +556,7 @@
      * @param action
      */
     public void requestDelete(int actionId, final Collection<Conversation> conversations,
-            final Collection<ConversationItemView> views, final DestructiveAction action) {
+            final DestructiveAction action) {
         for (Conversation conv : conversations) {
             conv.localDeleteOnUpdate = true;
         }
diff --git a/src/com/android/mail/ui/ConversationSelectionSet.java b/src/com/android/mail/ui/ConversationSelectionSet.java
index 75ad76a..4b70529 100644
--- a/src/com/android/mail/ui/ConversationSelectionSet.java
+++ b/src/com/android/mail/ui/ConversationSelectionSet.java
@@ -68,12 +68,6 @@
     private final HashMap<Long, Conversation> mInternalMap =
             new HashMap<Long, Conversation>();
 
-    /**
-     * Map of conversation IDs to {@link ConversationItemView} objects. The views are <b>not</b>
-     * updated when a new list view object is created on orientation change.
-     */
-    private final HashMap<Long, ConversationItemView> mInternalViewMap =
-            new HashMap<Long, ConversationItemView>();
     private final BiMap<String, Long> mConversationUriToIdMap = HashBiMap.create();
 
     @VisibleForTesting
@@ -107,7 +101,6 @@
     public void clear() {
         synchronized (mLock) {
             boolean initiallyNotEmpty = !mInternalMap.isEmpty();
-            mInternalViewMap.clear();
             mInternalMap.clear();
             mConversationUriToIdMap.clear();
 
@@ -187,9 +180,6 @@
         synchronized (mLock) {
             final boolean initiallyEmpty = mInternalMap.isEmpty();
             mInternalMap.put(id, info);
-            // Fill out the view map with null. The sizes will match, but
-            // we won't have any views available yet to store.
-            mInternalViewMap.put(id, null);
             mConversationUriToIdMap.put(info.uri.toString(), id);
 
             final ArrayList<ConversationSetObserver> observersCopy = Lists.newArrayList(mObservers);
@@ -203,8 +193,7 @@
     /** @see java.util.HashMap#put */
     private void put(Long id, ConversationItemView info) {
         synchronized (mLock) {
-            boolean initiallyEmpty = mInternalMap.isEmpty();
-            mInternalViewMap.put(id, info);
+            final boolean initiallyEmpty = mInternalMap.isEmpty();
             mInternalMap.put(id, info.mHeader.conversation);
             mConversationUriToIdMap.put(info.mHeader.conversation.uri.toString(), id);
 
@@ -230,7 +219,6 @@
             final BiMap<Long, String> inverseMap = mConversationUriToIdMap.inverse();
 
             for (Long id : ids) {
-                mInternalViewMap.remove(id);
                 mInternalMap.remove(id);
                 inverseMap.remove(id);
             }
@@ -310,14 +298,7 @@
         final boolean initiallyEmpty = mInternalMap.isEmpty();
         mInternalMap.putAll(other.mInternalMap);
 
-        final Set<Long> keys = other.mInternalMap.keySet();
-        for (Long key : keys) {
-            // Fill out the view map with null. The sizes will match, but
-            // we won't have any views available yet to store.
-            mInternalViewMap.put(key, null);
-        }
-
-        ArrayList<ConversationSetObserver> observersCopy = Lists.newArrayList(mObservers);
+        final ArrayList<ConversationSetObserver> observersCopy = Lists.newArrayList(mObservers);
         dispatchOnChange(observersCopy);
         if (initiallyEmpty) {
             dispatchOnBecomeUnempty(observersCopy);
@@ -330,10 +311,6 @@
         dest.writeParcelableArray(values, flags);
     }
 
-    public Collection<ConversationItemView> views() {
-        return mInternalViewMap.values();
-    }
-
     /**
      * @param deletedRows an arraylist of conversation IDs which have been deleted.
      */
diff --git a/src/com/android/mail/ui/ConversationUpdater.java b/src/com/android/mail/ui/ConversationUpdater.java
index 3e16a36..fe7f621 100644
--- a/src/com/android/mail/ui/ConversationUpdater.java
+++ b/src/com/android/mail/ui/ConversationUpdater.java
@@ -87,18 +87,6 @@
             int actionId, final Collection<Conversation> target, final DestructiveAction action);
 
     /**
-     * Requests the removal of the current conversation with the specified
-     * destructive action.
-     * @param actionId TODO(viki):
-     * @param target the conversations to act upon.
-     *@param target the conversation views to act upon.
-     * @param action to perform after the UI has been updated to remove the
-     *            conversations
-     */
-    void delete(int actionId, final Collection<Conversation> target,
-            final Collection<ConversationItemView> targetViews, final DestructiveAction action);
-
-    /**
      * Mark a number of conversations as read or unread.
      * @param targets the conversations to act upon
      * @param read true if the conversations are marked read, false if they are marked unread.