From b41c826c6ac18dc66a5bdcb76d43e68a87474d11 Mon Sep 17 00:00:00 2001 From: fbaron Date: Wed, 13 Mar 2024 12:14:25 -0700 Subject: [PATCH] Fix bug where folder with 1 icon can exist Fix: 329357132 Flag: NONE Test: TaplDragTest Change-Id: If381ff56e051c89e9f6162f8a44f8df9e2ae5060 (cherry picked from commit 5645c3ec558e2b0b6d6ae1c51dbaf93803cd51cf) --- src/com/android/launcher3/folder/Folder.java | 3 +++ .../android/launcher3/dragging/TaplDragTest.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index ec9c27dfab..ecb5c8f186 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -1039,6 +1039,9 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo public void onDropCompleted(final View target, final DragObject d, final boolean success) { if (success) { + if (getItemCount() <= 1) { + mDeleteFolderOnDropCompleted = true; + } if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) { replaceFolderWithFinalItem(); } diff --git a/tests/src/com/android/launcher3/dragging/TaplDragTest.java b/tests/src/com/android/launcher3/dragging/TaplDragTest.java index d1227d8693..bf1ba39fef 100644 --- a/tests/src/com/android/launcher3/dragging/TaplDragTest.java +++ b/tests/src/com/android/launcher3/dragging/TaplDragTest.java @@ -96,6 +96,21 @@ public class TaplDragTest extends AbstractLauncherUiTest { MAPS_APP_NAME); } + /** + * Adds two icons to the Workspace and combines them into a folder, then makes sure we are able + * to remove an icon from the folder and that the folder ceases to exist since it only has one + * icon left. + */ + @Test + public void testDragOutOfFolder() { + final HomeAppIcon playStoreIcon = createShortcutIfNotExist(STORE_APP_NAME, 0, 1); + final HomeAppIcon photosIcon = createShortcutInCenterIfNotExist(PHOTOS_APP_NAME); + FolderIcon folderIcon = photosIcon.dragToIcon(playStoreIcon); + Folder folder = folderIcon.open(); + folder.getAppIcon(STORE_APP_NAME).internalDragToWorkspace(false, false); + assertNotNull(mLauncher.getWorkspace().tryGetWorkspaceAppIcon(STORE_APP_NAME)); + assertNotNull(mLauncher.getWorkspace().tryGetWorkspaceAppIcon(PHOTOS_APP_NAME)); + } /** Drags a shortcut from a long press menu into the workspace. * 1. Open all apps and wait for load complete.