Moving bindAppsAdded and setIsFirstPagePinnedItemEnabled to ModelCallbacks

Changes are part of go/launcher_SoR .

Flag: NA
Bug: 301108526
Test: This is a no-op change, compiling should be the test
Change-Id: I79a651c9d57e443037e330728540616b0d01434a
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 22870bc..da86336 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -27,7 +27,6 @@
 import static com.android.launcher3.AbstractFloatingView.TYPE_ICON_SURFACE;
 import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
 import static com.android.launcher3.AbstractFloatingView.getTopOpenViewWithType;
-import static com.android.launcher3.BuildConfig.QSB_ON_FIRST_SCREEN;
 import static com.android.launcher3.LauncherAnimUtils.HOTSEAT_SCALE_PROPERTY_FACTORY;
 import static com.android.launcher3.LauncherAnimUtils.SCALE_INDEX_WIDGET_TRANSITION;
 import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
@@ -65,11 +64,9 @@
 import static com.android.launcher3.LauncherState.NO_SCALE;
 import static com.android.launcher3.LauncherState.SPRING_LOADED;
 import static com.android.launcher3.Utilities.postAsyncCallback;
-import static com.android.launcher3.WorkspaceLayoutManager.FIRST_SCREEN_ID;
 import static com.android.launcher3.config.FeatureFlags.ENABLE_SMARTSPACE_REMOVAL;
 import static com.android.launcher3.config.FeatureFlags.FOLDABLE_SINGLE_PAGE;
 import static com.android.launcher3.config.FeatureFlags.MULTI_SELECT_EDIT_MODE;
-import static com.android.launcher3.config.FeatureFlags.shouldShowFirstPageWidget;
 import static com.android.launcher3.logging.StatsLogManager.EventEnum;
 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;
 import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME;
@@ -403,12 +400,8 @@
     // session on the server side.
     protected InstanceId mAllAppsSessionLogId;
     private LauncherState mPrevLauncherState;
-
-    private StringCache mStringCache;
     private StartupLatencyLogger mStartupLatencyLogger;
     private CellPosMapper mCellPosMapper = CellPosMapper.DEFAULT;
-    private boolean mIsFirstPagePinnedItemEnabled = QSB_ON_FIRST_SCREEN
-            && !ENABLE_SMARTSPACE_REMOVAL.get();
 
     private final CannedAnimationCoordinator mAnimationCoordinator =
             new CannedAnimationCoordinator(this);
@@ -2126,32 +2119,12 @@
 
     @Override
     public void setIsFirstPagePinnedItemEnabled(boolean isFirstPagePinnedItemEnabled) {
-        mIsFirstPagePinnedItemEnabled = isFirstPagePinnedItemEnabled;
-        mWorkspace.bindAndInitFirstWorkspaceScreen();
+        mModelCallbacks.setIsFirstPagePinnedItemEnabled(isFirstPagePinnedItemEnabled);
     }
 
     @Override
     public void bindScreens(IntArray orderedScreenIds) {
-        mWorkspace.mPageIndicator.setAreScreensBinding(true, mDeviceProfile.isTwoPanels);
-        int firstScreenPosition = 0;
-        if ((FeatureFlags.QSB_ON_FIRST_SCREEN
-                && mIsFirstPagePinnedItemEnabled
-                && !shouldShowFirstPageWidget())
-                && orderedScreenIds.indexOf(FIRST_SCREEN_ID) != firstScreenPosition) {
-            orderedScreenIds.removeValue(FIRST_SCREEN_ID);
-            orderedScreenIds.add(firstScreenPosition, FIRST_SCREEN_ID);
-        } else if (((!FeatureFlags.QSB_ON_FIRST_SCREEN && !mIsFirstPagePinnedItemEnabled)
-                || shouldShowFirstPageWidget())
-                && orderedScreenIds.isEmpty()) {
-            // If there are no screens, we need to have an empty screen
-            mWorkspace.addExtraEmptyScreens();
-        }
-        bindAddScreens(orderedScreenIds);
-
-        // After we have added all the screens, if the wallpaper was locked to the default state,
-        // then notify to indicate that it can be released and a proper wallpaper offset can be
-        // computed before the next layout
-        mWorkspace.unlockWallpaperFromDefaultPageOnNextLayout();
+        mModelCallbacks.bindScreens(orderedScreenIds);
     }
 
     /**
@@ -2172,35 +2145,6 @@
         return screenIds.getArray();
     }
 
-    private void bindAddScreens(IntArray orderedScreenIds) {
-
-        if (mDeviceProfile.isTwoPanels) {
-            if (FOLDABLE_SINGLE_PAGE.get()) {
-                orderedScreenIds = filterTwoPanelScreenIds(orderedScreenIds);
-            } else {
-                // Some empty pages might have been removed while the phone was in a single panel
-                // mode, so we want to add those empty pages back.
-                IntSet screenIds = IntSet.wrap(orderedScreenIds);
-                orderedScreenIds.forEach(
-                        screenId -> screenIds.add(mWorkspace.getScreenPair(screenId)));
-                orderedScreenIds = screenIds.getArray();
-            }
-        }
-
-        int count = orderedScreenIds.size();
-        for (int i = 0; i < count; i++) {
-            int screenId = orderedScreenIds.get(i);
-            if (FeatureFlags.QSB_ON_FIRST_SCREEN
-                    && mIsFirstPagePinnedItemEnabled
-                    && !shouldShowFirstPageWidget()
-                    && screenId == FIRST_SCREEN_ID) {
-                // No need to bind the first screen, as its always bound.
-                continue;
-            }
-            mWorkspace.insertNewWorkspaceScreenBeforeEmptyScreen(screenId);
-        }
-    }
-
     @Override
     public void preAddApps() {
         mModelCallbacks.preAddApps();
@@ -2209,25 +2153,7 @@
     @Override
     public void bindAppsAdded(IntArray newScreens, ArrayList<ItemInfo> addNotAnimated,
             ArrayList<ItemInfo> addAnimated) {
-        // Add the new screens
-        if (newScreens != null) {
-            // newScreens can contain an empty right panel that is already bound, but not known
-            // by BgDataModel.
-            newScreens.removeAllValues(mWorkspace.mScreenOrder);
-            bindAddScreens(newScreens);
-        }
-
-        // We add the items without animation on non-visible pages, and with
-        // animations on the new page (which we will try and snap to).
-        if (addNotAnimated != null && !addNotAnimated.isEmpty()) {
-            bindItems(addNotAnimated, false);
-        }
-        if (addAnimated != null && !addAnimated.isEmpty()) {
-            bindItems(addAnimated, true);
-        }
-
-        // Remove the extra empty screen
-        mWorkspace.removeExtraEmptyScreen(false);
+        mModelCallbacks.bindAppsAdded(newScreens, addNotAnimated, addAnimated);
     }
 
     /**
@@ -2877,8 +2803,7 @@
 
     @Override
     public void bindStringCache(StringCache cache) {
-        mStringCache = cache;
-        mAppsView.updateWorkUI();
+        mModelCallbacks.bindStringCache(cache);
     }
 
     /**
@@ -3314,7 +3239,7 @@
 
     @Override
     public StringCache getStringCache() {
-        return mStringCache;
+        return mModelCallbacks.getStringCache();
     }
 
     /**
@@ -3349,7 +3274,7 @@
     }
 
     public boolean getIsFirstPagePinnedItemEnabled() {
-        return mIsFirstPagePinnedItemEnabled;
+        return mModelCallbacks.getIsFirstPagePinnedItemEnabled();
     }
 
     /**