Fix for issue 7178173, item disappearing from folder

Change-Id: I8e4e2f04053a2fc29ca38dc130f39c57c5c019f7
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index c58189c..ee15008 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -690,22 +690,21 @@
                 replaceFolderWithFinalItem();
             }
         } else {
+            setupContentForNumItems(getItemCount());
             // The drag failed, we need to return the item to the folder
             mFolderIcon.onDrop(d);
-
-            // We're going to trigger a "closeFolder" which may occur before this item has
-            // been added back to the folder -- this could cause the folder to be deleted
-            if (mOnExitAlarm.alarmPending()) {
-                mSuppressFolderDeletion = true;
-            }
         }
 
         if (target != this) {
             if (mOnExitAlarm.alarmPending()) {
                 mOnExitAlarm.cancelAlarm();
+                if (!success) {
+                    mSuppressFolderDeletion = true;
+                }
                 completeDragExit();
             }
         }
+
         mDeleteFolderOnDropCompleted = false;
         mDragInProgress = false;
         mItemAddedBackToSelfViaIcon = false;
@@ -1024,6 +1023,18 @@
         mInfo.add(item);
     }
 
+    // This is used so the item doesn't immediately appear in the folder when added. In one case
+    // we need to create the illusion that the item isn't added back to the folder yet, to
+    // to correspond to the animation of the icon back into the folder. This is
+    public void hideItem(ShortcutInfo info) {
+        View v = getViewForInfo(info);
+        v.setVisibility(INVISIBLE);
+    }
+    public void showItem(ShortcutInfo info) {
+        View v = getViewForInfo(info);
+        v.setVisibility(VISIBLE);
+    }
+
     public void onAdd(ShortcutInfo item) {
         mItemsInvalidated = true;
         // If the item was dropped onto this open folder, we have done the work associated
@@ -1076,20 +1087,13 @@
     }
 
     public ArrayList<View> getItemsInReadingOrder() {
-        return getItemsInReadingOrder(true);
-    }
-
-    public ArrayList<View> getItemsInReadingOrder(boolean includeCurrentDragItem) {
         if (mItemsInvalidated) {
             mItemsInReadingOrder.clear();
             for (int j = 0; j < mContent.getCountY(); j++) {
                 for (int i = 0; i < mContent.getCountX(); i++) {
                     View v = mContent.getChildAt(i, j);
                     if (v != null) {
-                        ShortcutInfo info = (ShortcutInfo) v.getTag();
-                        if (info != mCurrentDragInfo || includeCurrentDragItem) {
-                            mItemsInReadingOrder.add(v);
-                        }
+                        mItemsInReadingOrder.add(v);
                     }
                 }
             }
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
index 76374d2..33650c5 100644
--- a/src/com/android/launcher2/FolderIcon.java
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -402,9 +402,11 @@
                     postAnimationRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
             addItem(item);
             mHiddenItems.add(item);
+            mFolder.hideItem(item);
             postDelayed(new Runnable() {
                 public void run() {
                     mHiddenItems.remove(item);
+                    mFolder.showItem(item);
                     invalidate();
                 }
             }, DROP_IN_ANIMATION_DURATION);
@@ -535,7 +537,7 @@
         if (mFolder == null) return;
         if (mFolder.getItemCount() == 0 && !mAnimating) return;
 
-        ArrayList<View> items = mFolder.getItemsInReadingOrder(false);
+        ArrayList<View> items = mFolder.getItemsInReadingOrder();
         Drawable d;
         TextView v;