From 44c06437e2e0476e24b61891d1a4aca9828f5327 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Sat, 2 Apr 2016 10:56:02 -0700 Subject: [PATCH] Fixing bug where folders on the first screen and hotseat are not registered by the Launcher if there are folders on other screens Instead of maintaing a static map of folder items, searching it in the workspace during item removal. Change-Id: I8aa93b3aa1d0bd812204471e3103f4bd29d1cd3d --- src/com/android/launcher3/Launcher.java | 33 +-------- src/com/android/launcher3/LauncherModel.java | 71 +++----------------- 2 files changed, 12 insertions(+), 92 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 7311cce031..06d16945f0 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -288,8 +288,6 @@ public class Launcher extends Activity private LauncherClings mClings; - private static LongArrayMap sFolders = new LongArrayMap<>(); - private View.OnTouchListener mHapticFeedbackTouchListener; // Related to the auto-advancing of widgets @@ -2349,7 +2347,6 @@ public class Launcher extends Activity // Update the model LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY); - sFolders.put(folderInfo.id, folderInfo); // Create the view FolderIcon newFolder = @@ -2372,9 +2369,9 @@ public class Launcher extends Activity public boolean removeItem(View v, ItemInfo itemInfo, boolean deleteFromDb) { if (itemInfo instanceof ShortcutInfo) { // Remove the shortcut from the folder before removing it from launcher - FolderInfo folderInfo = sFolders.get(itemInfo.container); - if (folderInfo != null) { - folderInfo.remove((ShortcutInfo) itemInfo); + View folderIcon = mWorkspace.getHomescreenIconByItemId(itemInfo.container); + if (folderIcon instanceof FolderIcon) { + ((FolderInfo) folderIcon.getTag()).remove((ShortcutInfo) itemInfo); } else { mWorkspace.removeWorkspaceItem(v); } @@ -2383,7 +2380,6 @@ public class Launcher extends Activity } } else if (itemInfo instanceof FolderInfo) { final FolderInfo folderInfo = (FolderInfo) itemInfo; - unbindFolder(folderInfo); mWorkspace.removeWorkspaceItem(v); if (deleteFromDb) { LauncherModel.deleteFolderAndContentsFromDatabase(this, folderInfo); @@ -2403,13 +2399,6 @@ public class Launcher extends Activity return true; } - /** - * Unbinds any launcher references to the folder. - */ - private void unbindFolder(FolderInfo folder) { - sFolders.remove(folder.id); - } - /** * Deletes the widget info and the widget id. */ @@ -3905,21 +3894,6 @@ public class Launcher extends Activity workspace.requestLayout(); } - /** - * Implementation of the method from LauncherModel.Callbacks. - */ - public void bindFolders(final LongArrayMap folders) { - Runnable r = new Runnable() { - public void run() { - bindFolders(folders); - } - }; - if (waitUntilResume(r)) { - return; - } - sFolders = folders.clone(); - } - private void bindSafeModeWidget(LauncherAppWidgetInfo item) { PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true); view.updateIcon(mIconCache); @@ -4698,7 +4672,6 @@ public class Launcher extends Activity Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); Log.d(TAG, "mRestoring=" + mRestoring); Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); - Log.d(TAG, "sFolders.size=" + sFolders.size()); mModel.dumpState(); // TODO(hyunyoungs): add mWidgetsView.dumpState(); or mWidgetsModel.dumpState(); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 030c6e2d05..97b46015fa 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -184,7 +184,6 @@ public class LauncherModel extends BroadcastReceiver boolean forceAnimateIcons); public void bindScreens(ArrayList orderedScreenIds); public void bindAddScreens(ArrayList orderedScreenIds); - public void bindFolders(LongArrayMap folders); public void finishBindingItems(); public void bindAppWidget(LauncherAppWidgetInfo info); public void bindAllApplications(ArrayList apps); @@ -2348,29 +2347,6 @@ public class LauncherModel extends BroadcastReceiver } } - /** Filters the set of folders which are on the specified screen. */ - private void filterCurrentFolders(long currentScreenId, - LongArrayMap itemsIdMap, - LongArrayMap folders, - LongArrayMap currentScreenFolders, - LongArrayMap otherScreenFolders) { - - int total = folders.size(); - for (int i = 0; i < total; i++) { - long id = folders.keyAt(i); - FolderInfo folder = folders.valueAt(i); - - ItemInfo info = itemsIdMap.get(id); - if (info == null || folder == null) continue; - if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && - info.screenId == currentScreenId) { - currentScreenFolders.put(id, folder); - } else { - otherScreenFolders.put(id, folder); - } - } - } - /** Sorts the set of items by hotseat, workspace (spatially from top to bottom, left to * right) */ private void sortWorkspaceItemsSpatially(ArrayList workspaceItems) { @@ -2427,7 +2403,6 @@ public class LauncherModel extends BroadcastReceiver private void bindWorkspaceItems(final Callbacks oldCallbacks, final ArrayList workspaceItems, final ArrayList appWidgets, - final LongArrayMap folders, final Executor executor) { // Bind the workspace items @@ -2448,19 +2423,6 @@ public class LauncherModel extends BroadcastReceiver executor.execute(r); } - // Bind the folders - if (!folders.isEmpty()) { - final Runnable r = new Runnable() { - public void run() { - Callbacks callbacks = tryGetCallbacks(oldCallbacks); - if (callbacks != null) { - callbacks.bindFolders(folders); - } - } - }; - executor.execute(r); - } - // Bind the widgets, one at a time N = appWidgets.size(); for (int i = 0; i < N; i++) { @@ -2494,21 +2456,14 @@ public class LauncherModel extends BroadcastReceiver } // Save a copy of all the bg-thread collections - ArrayList workspaceItems = new ArrayList(); - ArrayList appWidgets = - new ArrayList(); - ArrayList orderedScreenIds = new ArrayList(); - - final LongArrayMap folders; - final LongArrayMap itemsIdMap; + ArrayList workspaceItems = new ArrayList<>(); + ArrayList appWidgets = new ArrayList<>(); + ArrayList orderedScreenIds = new ArrayList<>(); synchronized (sBgLock) { workspaceItems.addAll(sBgWorkspaceItems); appWidgets.addAll(sBgAppWidgets); orderedScreenIds.addAll(sBgWorkspaceScreens); - - folders = sBgFolders.clone(); - itemsIdMap = sBgItemsIdMap.clone(); } final boolean isLoadingSynchronously = @@ -2528,21 +2483,15 @@ public class LauncherModel extends BroadcastReceiver unbindWorkspaceItemsOnMainThread(); // Separate the items that are on the current screen, and all the other remaining items - ArrayList currentWorkspaceItems = new ArrayList(); - ArrayList otherWorkspaceItems = new ArrayList(); - ArrayList currentAppWidgets = - new ArrayList(); - ArrayList otherAppWidgets = - new ArrayList(); - LongArrayMap currentFolders = new LongArrayMap<>(); - LongArrayMap otherFolders = new LongArrayMap<>(); + ArrayList currentWorkspaceItems = new ArrayList<>(); + ArrayList otherWorkspaceItems = new ArrayList<>(); + ArrayList currentAppWidgets = new ArrayList<>(); + ArrayList otherAppWidgets = new ArrayList<>(); filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems, otherWorkspaceItems); filterCurrentAppWidgets(currentScreenId, appWidgets, currentAppWidgets, otherAppWidgets); - filterCurrentFolders(currentScreenId, itemsIdMap, folders, currentFolders, - otherFolders); sortWorkspaceItemsSpatially(currentWorkspaceItems); sortWorkspaceItemsSpatially(otherWorkspaceItems); @@ -2562,8 +2511,7 @@ public class LauncherModel extends BroadcastReceiver Executor mainExecutor = new DeferredMainThreadExecutor(); // Load items on the current page. - bindWorkspaceItems(oldCallbacks, currentWorkspaceItems, currentAppWidgets, - currentFolders, mainExecutor); + bindWorkspaceItems(oldCallbacks, currentWorkspaceItems, currentAppWidgets, mainExecutor); // In case of isLoadingSynchronously, only bind the first screen, and defer binding the // remaining screens after first onDraw is called. This ensures that the first screen @@ -2572,8 +2520,7 @@ public class LauncherModel extends BroadcastReceiver final Executor deferredExecutor = isLoadingSynchronously ? new ViewOnDrawExecutor(mHandler) : mainExecutor; - bindWorkspaceItems(oldCallbacks, otherWorkspaceItems, otherAppWidgets, - otherFolders, deferredExecutor); + bindWorkspaceItems(oldCallbacks, otherWorkspaceItems, otherAppWidgets, deferredExecutor); // Tell the workspace that we're done binding items r = new Runnable() {