From 6febe1f3613a3b994fa4a2bfad3a14f80f3b0126 Mon Sep 17 00:00:00 2001 From: Winson Date: Fri, 2 Oct 2015 17:14:14 -0700 Subject: [PATCH] Fixing regression when removing last item from folder. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The regression caused the folder and all its contents to be removed before the new item could be moved to the place of the folder. In addition, in this case, the LauncherModel would get out of sync with the db because we move the last item to the workspace, but don’t remove it from the contents, so deleting the folder would remove the item’s mapping in sBgItemIdMap. Bug: 24620815 Change-Id: I17137f28b0f1617a890488c7a9c5b8a9e8df0e91 --- src/com/android/launcher3/Folder.java | 40 +++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java index 1499a27369..18918612c3 100644 --- a/src/com/android/launcher3/Folder.java +++ b/src/com/android/launcher3/Folder.java @@ -1116,31 +1116,37 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList Runnable onCompleteRunnable = new Runnable() { @Override public void run() { - CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, mInfo.screenId); + int itemCount = getItemCount(); + if (itemCount <= 1) { + View newIcon = null; - // Remove the folder - if (getItemCount() <= 1) { + if (itemCount == 1) { + // Move the item from the folder to the workspace, in the position of the + // folder + CellLayout cellLayout = mLauncher.getCellLayout(mInfo.container, + mInfo.screenId); + ShortcutInfo finalItem = mInfo.contents.remove(0); + newIcon = mLauncher.createShortcut(cellLayout, finalItem); + LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, + mInfo.screenId, mInfo.cellX, mInfo.cellY); + } + + // Remove the folder mLauncher.removeItem(mFolderIcon, mInfo, true /* deleteFromDb */); if (mFolderIcon instanceof DropTarget) { mDragController.removeDropTarget((DropTarget) mFolderIcon); } - } - // Move the item from the folder to the workspace, in the position of the folder - if (getItemCount() == 1) { - ShortcutInfo finalItem = mInfo.contents.get(0); - View child = mLauncher.createShortcut(cellLayout, finalItem); - LauncherModel.addOrMoveItemInDatabase(mLauncher, finalItem, mInfo.container, - mInfo.screenId, mInfo.cellX, mInfo.cellY); - - // We add the child after removing the folder to prevent both from existing at - // the same time in the CellLayout. We need to add the new item with addInScreenFromBind() - // to ensure that hotseat items are placed correctly. - mLauncher.getWorkspace().addInScreenFromBind(child, mInfo.container, mInfo.screenId, - mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); + if (newIcon != null) { + // We add the child after removing the folder to prevent both from existing + // at the same time in the CellLayout. We need to add the new item with + // addInScreenFromBind() to ensure that hotseat items are placed correctly. + mLauncher.getWorkspace().addInScreenFromBind(newIcon, mInfo.container, + mInfo.screenId, mInfo.cellX, mInfo.cellY, mInfo.spanX, mInfo.spanY); + } // Focus the newly created child - child.requestFocus(); + newIcon.requestFocus(); } } };