Make sure we can have > 1 fading out leave behind items

A user could swipe a conversation away, and then just keep swiping
We need to make sure that as they do that, we have the old
fading leave behind items keep fading out and just add new ones to the list.

Removes a few unnecessary styles.

Makes sure we don't restart animations on fading leave behinds.
Change-Id: I8927339a9c4d78304b98f2322fdd7c5dab484cdb
diff --git a/res/layout/swipe_leavebehind.xml b/res/layout/swipe_leavebehind.xml
index 4c3c371..ea69286 100644
--- a/res/layout/swipe_leavebehind.xml
+++ b/res/layout/swipe_leavebehind.xml
@@ -54,7 +54,6 @@
         android:layout_height="match_parent"
         android:layout_gravity="center_vertical"
         android:layout_marginRight="8dip"
-        android:layout_toRightOf="@id/undo_separator"
         android:src="@drawable/ic_menu_revert_holo_dark" />
 
     <TextView
@@ -62,7 +61,6 @@
         style="@style/UndoTextStyle"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
-        android:layout_toRightOf="@id/undo_icon"
         android:gravity="center_vertical"
         android:paddingRight="16dip"
         android:text="@string/undo"
diff --git a/src/com/android/mail/ui/AnimatedAdapter.java b/src/com/android/mail/ui/AnimatedAdapter.java
index 3029483..b0935e1 100644
--- a/src/com/android/mail/ui/AnimatedAdapter.java
+++ b/src/com/android/mail/ui/AnimatedAdapter.java
@@ -60,6 +60,8 @@
     private final HashSet<Integer> mSwipeUndoingItems = new HashSet<Integer>();
     private final HashMap<Long, SwipeableConversationItemView> mAnimatingViews =
             new HashMap<Long, SwipeableConversationItemView>();
+    private HashMap<Long, LeaveBehindItem> mFadeLeaveBehindItems =
+            new HashMap<Long, LeaveBehindItem>();
     /** The current account */
     private final Account mAccount;
     private final Context mContext;
@@ -91,7 +93,6 @@
     private final SwipeableListView mListView;
     private Settings mCachedSettings;
     private final boolean mSwipeEnabled;
-    private LeaveBehindItem mFadeLeaveBehindItem;
     private LeaveBehindItem mLeaveBehindItem;
     /** True if priority inbox markers are enabled, false otherwise. */
     private final boolean mPriorityMarkersEnabled;
@@ -297,7 +298,7 @@
     }
 
     private boolean hasFadeLeaveBehinds() {
-        return mFadeLeaveBehindItem != null;
+        return !mFadeLeaveBehindItems.isEmpty();
     }
 
     public LeaveBehindItem setupLeaveBehind(Conversation target, ToastBarOperation undoOp,
@@ -326,7 +327,7 @@
             // it.
             Conversation conv = mLeaveBehindItem.getData();
             if (conv.position >= startPosition && conv.position <= endPosition) {
-                mFadeLeaveBehindItem = mLeaveBehindItem;
+                mFadeLeaveBehindItems.put(conv.id, mLeaveBehindItem);
             }
             clearLeaveBehind(conv.id);
         }
@@ -342,7 +343,9 @@
             mLeaveBehindItem.commit();
         }
         if (hasFadeLeaveBehinds()) {
-            mFadeLeaveBehindItem.commit();
+            for (LeaveBehindItem item : mFadeLeaveBehindItems.values()) {
+                item.commit();
+            }
         }
         if (!mLastDeletingItems.isEmpty()) {
             mLastDeletingItems.clear();
@@ -355,7 +358,7 @@
     }
 
     private LeaveBehindItem getFadeLeaveBehindItem(int position, Conversation target) {
-        return mFadeLeaveBehindItem;
+        return mFadeLeaveBehindItems.get(target.id);
     }
 
     @Override
@@ -440,7 +443,7 @@
 
     private boolean isPositionFadeLeaveBehind(Conversation conv) {
         return hasFadeLeaveBehinds()
-                && mFadeLeaveBehindItem.getConversationId() == conv.id
+                && mFadeLeaveBehindItems.containsKey(conv.id)
                 && conv.isMostlyDead();
     }
 
@@ -565,8 +568,8 @@
     public void clearLeaveBehind(long itemId) {
         if (hasLeaveBehinds() && mLeaveBehindItem.getConversationId() == itemId) {
             mLeaveBehindItem = null;
-        } else if (hasFadeLeaveBehinds() && mFadeLeaveBehindItem.getConversationId() == itemId) {
-            mFadeLeaveBehindItem = null;
+        } else if (hasFadeLeaveBehinds()) {
+            mFadeLeaveBehindItems.remove(itemId);
         } else {
             LogUtils.d(LOG_TAG, "Trying to clear a non-existant leave behind");
         }
@@ -613,7 +616,7 @@
     public boolean isAnimating() {
         return !mUndoingItems.isEmpty()
                 || !mSwipeUndoingItems.isEmpty()
-                || mFadeLeaveBehindItem != null
+                || !mFadeLeaveBehindItems.isEmpty()
                 || !mDeletingItems.isEmpty()
                 || !mSwipeDeletingItems.isEmpty();
     }
diff --git a/src/com/android/mail/ui/LeaveBehindItem.java b/src/com/android/mail/ui/LeaveBehindItem.java
index f7847db..b8a5e62 100644
--- a/src/com/android/mail/ui/LeaveBehindItem.java
+++ b/src/com/android/mail/ui/LeaveBehindItem.java
@@ -191,6 +191,7 @@
     private Conversation mData;
     private int mAnimatedHeight = -1;
     private int mWidth;
+    private boolean mAnimating;
 
     /**
      * Start the animation on an animating view.
@@ -200,17 +201,20 @@
      *            away during delete. Undoing populates the item.
      */
     public void startAnimation(ViewMode viewMode, AnimatorListener listener) {
-        int minHeight = ConversationItemViewCoordinates.getMinHeight(getContext(), viewMode);
-        setMinimumHeight(minHeight);
-        final int start = minHeight;
-        final int end = 0;
-        ObjectAnimator height = ObjectAnimator.ofInt(this, "animatedHeight", start, end);
-        mAnimatedHeight = start;
-        mWidth = getMeasuredWidth();
-        height.setInterpolator(new DecelerateInterpolator(2.0f));
-        height.addListener(listener);
-        height.setDuration(sShrinkAnimationDuration);
-        height.start();
+        if (!mAnimating) {
+            mAnimating = true;
+            int minHeight = ConversationItemViewCoordinates.getMinHeight(getContext(), viewMode);
+            setMinimumHeight(minHeight);
+            final int start = minHeight;
+            final int end = 0;
+            ObjectAnimator height = ObjectAnimator.ofInt(this, "animatedHeight", start, end);
+            mAnimatedHeight = start;
+            mWidth = getMeasuredWidth();
+            height.setInterpolator(new DecelerateInterpolator(2.0f));
+            height.addListener(listener);
+            height.setDuration(sShrinkAnimationDuration);
+            height.start();
+        }
     }
 
     public void setData(Conversation conversation) {