diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 2b433f152c..35977785e7 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -26,7 +26,6 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_ALL; import static com.android.launcher3.AbstractFloatingView.TYPE_FOLDER; import static com.android.launcher3.AbstractFloatingView.TYPE_ICON_SURFACE; import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE; -import static com.android.launcher3.AbstractFloatingView.TYPE_SNACKBAR; import static com.android.launcher3.AbstractFloatingView.getTopOpenViewWithType; import static com.android.launcher3.LauncherAnimUtils.HOTSEAT_SCALE_PROPERTY_FACTORY; import static com.android.launcher3.LauncherAnimUtils.SCALE_INDEX_WIDGET_TRANSITION; @@ -182,7 +181,6 @@ import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.pageindicators.WorkspacePageIndicator; import com.android.launcher3.pm.PinRequestHelper; import com.android.launcher3.popup.ArrowPopup; -import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.qsb.QsbContainerView; @@ -207,7 +205,6 @@ import com.android.launcher3.util.LockedUserState; import com.android.launcher3.util.OnboardingPrefs; import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.util.PendingRequestArgs; -import com.android.launcher3.util.Preconditions; import com.android.launcher3.util.RunnableList; import com.android.launcher3.util.ScreenOnTracker; import com.android.launcher3.util.ScreenOnTracker.ScreenOnListener; @@ -321,7 +318,7 @@ public class Launcher extends StatefulActivity @Thunk @VisibleForTesting public static final int NEW_APPS_ANIMATION_DELAY = 500; private static final String DISPLAY_WORKSPACE_TRACE_METHOD_NAME = "DisplayWorkspaceFirstFrame"; - private static final String DISPLAY_ALL_APPS_TRACE_METHOD_NAME = "DisplayAllApps"; + public static final String DISPLAY_ALL_APPS_TRACE_METHOD_NAME = "DisplayAllApps"; public static final int DISPLAY_WORKSPACE_TRACE_COOKIE = 0; public static final int DISPLAY_ALL_APPS_TRACE_COOKIE = 1; @@ -333,7 +330,11 @@ public class Launcher extends StatefulActivity private static final boolean DESKTOP_MODE_SUPPORTED = "1".equals(Utilities.getSystemProperty("persist.wm.debug.desktop_mode_2", "0")); - KeyboardShortcutsDelegate mKeyboardShortcutsDelegate = new KeyboardShortcutsDelegate(this); + private final ModelCallbacks mModelCallbacks = createModelCallbacks(); + + private final KeyboardShortcutsDelegate mKeyboardShortcutsDelegate = + new KeyboardShortcutsDelegate(this); + @Thunk Workspace mWorkspace; @Thunk @@ -593,6 +594,10 @@ public class Launcher extends StatefulActivity mStartupLatencyLogger.logEnd(LAUNCHER_LATENCY_STARTUP_ACTIVITY_ON_CREATE); } + protected ModelCallbacks createModelCallbacks() { + return new ModelCallbacks(this); + } + /** * Create {@link StartupLatencyLogger} that only collects launcher startup latency metrics * without sending them anywhere. Child class can override this method to create logger @@ -2239,13 +2244,7 @@ public class Launcher extends StatefulActivity @Override public void preAddApps() { - // If there's an undo snackbar, force it to complete to ensure empty screens are removed - // before trying to add new items. - mModelWriter.commitDelete(); - AbstractFloatingView snackbar = AbstractFloatingView.getOpenView(this, TYPE_SNACKBAR); - if (snackbar != null) { - snackbar.post(() -> snackbar.close(true)); - } + mModelCallbacks.preAddApps(); } @Override @@ -2843,90 +2842,70 @@ public class Launcher extends StatefulActivity public void onPageEndTransition() {} /** - * Add the icons for all apps. - * - * Implementation of the method from LauncherModel.Callbacks. + * See {@code LauncherBindingDelegate} */ @Override @TargetApi(Build.VERSION_CODES.S) @UiThread public void bindAllApplications(AppInfo[] apps, int flags, Map packageUserKeytoUidMap) { - Preconditions.assertUIThread(); - boolean hadWorkApps = mAppsView.shouldShowTabs(); - AllAppsStore appsStore = mAppsView.getAppsStore(); - appsStore.setApps(apps, flags, packageUserKeytoUidMap); - PopupContainerWithArrow.dismissInvalidPopup(this); - if (hadWorkApps != mAppsView.shouldShowTabs()) { - getStateManager().goToState(NORMAL); - } - + mModelCallbacks.bindAllApplications(apps, flags, packageUserKeytoUidMap); if (Utilities.ATLEAST_S) { - Trace.endAsyncSection(DISPLAY_ALL_APPS_TRACE_METHOD_NAME, - DISPLAY_ALL_APPS_TRACE_COOKIE); + Trace.endAsyncSection( + Launcher.DISPLAY_ALL_APPS_TRACE_METHOD_NAME, + Launcher.DISPLAY_ALL_APPS_TRACE_COOKIE + ); } } /** - * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary - * because LauncherModel's map is updated in the background, while Launcher runs on the UI. + * See {@code LauncherBindingDelegate} */ @Override public void bindDeepShortcutMap(HashMap deepShortcutMapCopy) { - mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy); + mModelCallbacks.bindDeepShortcutMap(deepShortcutMapCopy); } @Override public void bindIncrementalDownloadProgressUpdated(AppInfo app) { - mAppsView.getAppsStore().updateProgressBar(app); + mModelCallbacks.bindIncrementalDownloadProgressUpdated(app); } @Override public void bindWidgetsRestored(ArrayList widgets) { - mWorkspace.widgetsRestored(widgets); + mModelCallbacks.bindWidgetsRestored(widgets); } /** - * Some shortcuts were updated in the background. - * Implementation of the method from LauncherModel.Callbacks. - * - * @param updated list of shortcuts which have changed. + * See {@code LauncherBindingDelegate} */ @Override public void bindWorkspaceItemsChanged(List updated) { - if (!updated.isEmpty()) { - mWorkspace.updateWorkspaceItems(updated, this); - PopupContainerWithArrow.dismissInvalidPopup(this); - } + mModelCallbacks.bindWorkspaceItemsChanged(updated); } /** - * Update the state of a package, typically related to install state. - * - * Implementation of the method from LauncherModel.Callbacks. + * See {@code LauncherBindingDelegate} */ @Override public void bindRestoreItemsChange(HashSet updates) { - mWorkspace.updateRestoreItems(updates, this); + mModelCallbacks.bindRestoreItemsChange(updates); } /** - * A package was uninstalled/updated. We take both the super set of packageNames - * in addition to specific applications to remove, the reason being that - * this can be called when a package is updated as well. In that scenario, - * we only remove specific components from the workspace and hotseat, where as - * package-removal should clear all items by package name. + * See {@code LauncherBindingDelegate} */ @Override public void bindWorkspaceComponentsRemoved(Predicate matcher) { - mWorkspace.removeItemsByMatcher(matcher); - mDragController.onAppsRemoved(matcher); - PopupContainerWithArrow.dismissInvalidPopup(this); + mModelCallbacks.bindWorkspaceComponentsRemoved(matcher); } + /** + * See {@code LauncherBindingDelegate} + */ @Override public void bindAllWidgets(final List allWidgets) { - mPopupDataProvider.setAllWidgets(allWidgets); + mModelCallbacks.bindAllWidgets(allWidgets); } @Override @@ -3443,4 +3422,4 @@ public class Launcher extends StatefulActivity } // End of Getters and Setters -} +} \ No newline at end of file diff --git a/src/com/android/launcher3/ModelCallbacks.kt b/src/com/android/launcher3/ModelCallbacks.kt new file mode 100644 index 0000000000..679f7d401b --- /dev/null +++ b/src/com/android/launcher3/ModelCallbacks.kt @@ -0,0 +1,96 @@ +package com.android.launcher3 + +import androidx.annotation.UiThread +import com.android.launcher3.model.BgDataModel +import com.android.launcher3.model.data.AppInfo +import com.android.launcher3.model.data.ItemInfo +import com.android.launcher3.model.data.LauncherAppWidgetInfo +import com.android.launcher3.model.data.WorkspaceItemInfo +import com.android.launcher3.popup.PopupContainerWithArrow +import com.android.launcher3.util.ComponentKey +import com.android.launcher3.util.PackageUserKey +import com.android.launcher3.util.Preconditions +import com.android.launcher3.widget.model.WidgetsListBaseEntry +import java.util.function.Predicate + +class ModelCallbacks(private var launcher: Launcher) : BgDataModel.Callbacks { + override fun preAddApps() { + // If there's an undo snackbar, force it to complete to ensure empty screens are removed + // before trying to add new items. + launcher.modelWriter.commitDelete() + val snackbar = + AbstractFloatingView.getOpenView( + launcher, + AbstractFloatingView.TYPE_SNACKBAR + ) + snackbar?.post { snackbar.close(true) } + } + + @UiThread + override fun bindAllApplications( + apps: Array?, + flags: Int, + packageUserKeytoUidMap: Map? + ) { + Preconditions.assertUIThread() + val hadWorkApps = launcher.appsView.shouldShowTabs() + launcher.appsView.appsStore.setApps(apps, flags, packageUserKeytoUidMap) + PopupContainerWithArrow.dismissInvalidPopup(launcher) + if (hadWorkApps != launcher.appsView.shouldShowTabs()) { + launcher.stateManager.goToState(LauncherState.NORMAL) + } + } + + /** + * Copies LauncherModel's map of activities to shortcut counts to Launcher's. This is necessary + * because LauncherModel's map is updated in the background, while Launcher runs on the UI. + */ + override fun bindDeepShortcutMap(deepShortcutMapCopy: HashMap?) { + launcher.popupDataProvider.setDeepShortcutMap(deepShortcutMapCopy) + } + + override fun bindIncrementalDownloadProgressUpdated(app: AppInfo?) { + launcher.appsView.appsStore.updateProgressBar(app) + } + + override fun bindWidgetsRestored(widgets: ArrayList?) { + launcher.workspace.widgetsRestored(widgets) + } + + /** + * Some shortcuts were updated in the background. Implementation of the method from + * LauncherModel.Callbacks. + * + * @param updated list of shortcuts which have changed. + */ + override fun bindWorkspaceItemsChanged(updated: List) { + if (updated.isNotEmpty()) { + launcher.workspace.updateWorkspaceItems(updated, launcher) + PopupContainerWithArrow.dismissInvalidPopup(launcher) + } + } + + /** + * Update the state of a package, typically related to install state. Implementation of the + * method from LauncherModel.Callbacks. + */ + override fun bindRestoreItemsChange(updates: HashSet?) { + launcher.workspace.updateRestoreItems(updates, launcher) + } + + /** + * A package was uninstalled/updated. We take both the super set of packageNames in addition to + * specific applications to remove, the reason being that this can be called when a package is + * updated as well. In that scenario, we only remove specific components from the workspace and + * hotseat, where as package-removal should clear all items by package name. + */ + override fun bindWorkspaceComponentsRemoved(matcher: Predicate?) { + launcher.workspace.removeItemsByMatcher(matcher) + launcher.dragController.onAppsRemoved(matcher) + PopupContainerWithArrow.dismissInvalidPopup(launcher) + } + + override fun bindAllWidgets(allWidgets: List?) { + launcher.popupDataProvider.allWidgets = allWidgets + } +}