diff options
author | Tony Wickham <twickham@google.com> | 2016-09-23 00:35:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-09-23 00:35:13 +0000 |
commit | 8177ac7f8819dc5053f7683fc4b5d2b5cd0346ac (patch) | |
tree | ab4b2b1a9cb820f6de0883edee70140e71d69838 /src/com/android/launcher3/LauncherModel.java | |
parent | f2e075133ee1c705de16e99dfecf47871dd7abcb (diff) | |
parent | 7695e603bf1f4369115ba64c24e8b09c213b4e9c (diff) | |
download | android_packages_apps_Trebuchet-8177ac7f8819dc5053f7683fc4b5d2b5cd0346ac.tar.gz android_packages_apps_Trebuchet-8177ac7f8819dc5053f7683fc4b5d2b5cd0346ac.tar.bz2 android_packages_apps_Trebuchet-8177ac7f8819dc5053f7683fc4b5d2b5cd0346ac.zip |
Remove shortcuts that no longer exist or are no longer pinned.
am: 7695e603bf
Change-Id: I525c3342a7559f1cd831cbd4f56c2acd8b6875b9
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index a81231798..4afff1898 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -3169,40 +3169,55 @@ public class LauncherModel extends BroadcastReceiver public void run() { mDeepShortcutManager.onShortcutsChanged(mShortcuts); - Map<String, ShortcutInfoCompat> idsToShortcuts = new HashMap<>(); - for (ShortcutInfoCompat shortcut : mShortcuts) { - idsToShortcuts.put(shortcut.getId(), shortcut); - } - // Find ShortcutInfo's that have changed on the workspace. + final ArrayList<ShortcutInfo> removedShortcutInfos = new ArrayList<>(); MultiHashMap<String, ShortcutInfo> idsToWorkspaceShortcutInfos = new MultiHashMap<>(); for (ItemInfo itemInfo : sBgDataModel.itemsIdMap) { if (itemInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) { ShortcutInfo si = (ShortcutInfo) itemInfo; if (si.getPromisedIntent().getPackage().equals(mPackageName) && si.user.equals(mUser)) { - String shortcutId = si.getDeepShortcutId(); - if (idsToShortcuts.containsKey(shortcutId)) { - idsToWorkspaceShortcutInfos.addToList(shortcutId, si); - } + idsToWorkspaceShortcutInfos.addToList(si.getDeepShortcutId(), si); } } } - // Update the workspace to reflect the changes to updated shortcuts residing on it. - List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager.queryForFullDetails( - mPackageName, new ArrayList<>(idsToWorkspaceShortcutInfos.keySet()), mUser); - ArrayList<ShortcutInfo> updatedShortcutInfos = new ArrayList<>(); - Context context = LauncherAppState.getInstance().getContext(); - for (ShortcutInfoCompat fullDetails : shortcuts) { - List<ShortcutInfo> shortcutInfos = idsToWorkspaceShortcutInfos - .get(fullDetails.getId()); - for (ShortcutInfo shortcutInfo : shortcutInfos) { - shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context); - updatedShortcutInfos.add(shortcutInfo); + final Context context = LauncherAppState.getInstance().getContext(); + final ArrayList<ShortcutInfo> updatedShortcutInfos = new ArrayList<>(); + if (!idsToWorkspaceShortcutInfos.isEmpty()) { + // Update the workspace to reflect the changes to updated shortcuts residing on it. + List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager.queryForFullDetails( + mPackageName, new ArrayList<>(idsToWorkspaceShortcutInfos.keySet()), mUser); + for (ShortcutInfoCompat fullDetails : shortcuts) { + List<ShortcutInfo> shortcutInfos = idsToWorkspaceShortcutInfos + .remove(fullDetails.getId()); + if (!fullDetails.isPinned()) { + // The shortcut was previously pinned but is no longer, so remove it from + // the workspace and our pinned shortcut counts. + // Note that we put this check here, after querying for full details, + // because there's a possible race condition between pinning and + // receiving this callback. + removedShortcutInfos.addAll(shortcutInfos); + continue; + } + for (ShortcutInfo shortcutInfo : shortcutInfos) { + shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context); + updatedShortcutInfos.add(shortcutInfo); + } } } - bindUpdatedShortcuts(updatedShortcutInfos, mUser); + + // If there are still entries in idsToWorkspaceShortcutInfos, that means that + // the corresponding shortcuts weren't passed in onShortcutsChanged(). This + // means they were cleared, so we remove and unpin them now. + for (String id : idsToWorkspaceShortcutInfos.keySet()) { + removedShortcutInfos.addAll(idsToWorkspaceShortcutInfos.get(id)); + } + + bindUpdatedShortcuts(updatedShortcutInfos, removedShortcutInfos, mUser); + if (!removedShortcutInfos.isEmpty()) { + deleteItemsFromDatabase(context, removedShortcutInfos); + } if (mUpdateIdMap) { // Update the deep shortcut map if the list of ids has changed for an activity. |