Add app predictions to secondary display app drawer & fix tab UI.

Bug: 233926067
Test: Manual
Change-Id: I2f45a4b30964b365bf149e8864a3af2ea909a237
(cherry picked from commit 9e5fe63a2290b9c912bf50d66176a34b224f37e8)
Merged-In: I2f45a4b30964b365bf149e8864a3af2ea909a237
diff --git a/quickstep/res/values/override.xml b/quickstep/res/values/override.xml
index 705ec9d..4f472f0 100644
--- a/quickstep/res/values/override.xml
+++ b/quickstep/res/values/override.xml
@@ -25,4 +25,6 @@
 
   <string name="model_delegate_class" translatable="false">com.android.launcher3.model.QuickstepModelDelegate</string>
 
+  <string name="secondary_display_predictions_class" translatable="false">com.android.launcher3.secondarydisplay.SecondaryDisplayPredictionsImpl</string>
+
 </resources>
diff --git a/quickstep/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictionsImpl.java b/quickstep/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictionsImpl.java
new file mode 100644
index 0000000..5bf727a
--- /dev/null
+++ b/quickstep/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictionsImpl.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.secondarydisplay;
+
+import static com.android.launcher3.util.OnboardingPrefs.ALL_APPS_VISITED_COUNT;
+
+import android.content.Context;
+
+import com.android.launcher3.appprediction.AppsDividerView;
+import com.android.launcher3.appprediction.PredictionRowView;
+import com.android.launcher3.model.BgDataModel;
+import com.android.launcher3.util.OnboardingPrefs;
+import com.android.launcher3.views.ActivityContext;
+
+/**
+ * Implementation of SecondaryDisplayPredictions.
+ */
+@SuppressWarnings("unused")
+public final class SecondaryDisplayPredictionsImpl extends SecondaryDisplayPredictions {
+    private final ActivityContext mActivityContext;
+
+    public SecondaryDisplayPredictionsImpl(Context context) {
+        mActivityContext = ActivityContext.lookupContext(context);
+    }
+
+    @Override
+    void updateAppDivider() {
+        OnboardingPrefs<?> onboardingPrefs = mActivityContext.getOnboardingPrefs();
+        mActivityContext.getAppsView().getFloatingHeaderView()
+                .findFixedRowByType(AppsDividerView.class)
+                .setShowAllAppsLabel(!onboardingPrefs.hasReachedMaxCount(ALL_APPS_VISITED_COUNT));
+        onboardingPrefs.incrementEventCount(ALL_APPS_VISITED_COUNT);
+    }
+
+    @Override
+    public void setPredictedApps(BgDataModel.FixedContainerItems item) {
+        mActivityContext.getAppsView().getFloatingHeaderView()
+                .findFixedRowByType(PredictionRowView.class)
+                .setPredictedApps(item.items);
+    }
+}
diff --git a/res/layout/secondary_launcher.xml b/res/layout/secondary_launcher.xml
index 272d8d6..cccaa39 100644
--- a/res/layout/secondary_launcher.xml
+++ b/res/layout/secondary_launcher.xml
@@ -76,35 +76,8 @@
             android:paddingTop="@dimen/all_apps_header_top_padding"
             android:orientation="vertical" >
 
-            <com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip
-                android:id="@+id/tabs"
-                android:layout_width="match_parent"
-                android:layout_height="@dimen/all_apps_header_pill_height"
-                android:orientation="horizontal"
-                style="@style/TextHeadline">
-
-                <Button
-                    android:id="@+id/tab_personal"
-                    android:layout_width="0dp"
-                    android:layout_height="match_parent"
-                    android:layout_weight="1"
-                    android:background="?android:attr/selectableItemBackground"
-                    android:text="@string/all_apps_personal_tab"
-                    android:textAllCaps="true"
-                    android:textColor="@color/all_apps_tab_text"
-                    android:textSize="14sp" />
-
-                <Button
-                    android:id="@+id/tab_work"
-                    android:layout_width="0dp"
-                    android:layout_height="match_parent"
-                    android:layout_weight="1"
-                    android:background="?android:attr/selectableItemBackground"
-                    android:text="@string/all_apps_work_tab"
-                    android:textAllCaps="true"
-                    android:textColor="@color/all_apps_tab_text"
-                    android:textSize="14sp" />
-            </com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip>
+            <include layout="@layout/floating_header_content" />
+            <include layout="@layout/all_apps_personal_work_tabs" />
         </com.android.launcher3.allapps.FloatingHeaderView>
 
         <com.android.launcher3.allapps.search.AppsSearchContainerLayout
diff --git a/res/values/config.xml b/res/values/config.xml
index 1415ed0..d4c08d0 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -85,6 +85,7 @@
     <string name="launcher_activity_logic_class" translatable="false"></string>
     <string name="model_delegate_class" translatable="false"></string>
     <string name="window_manager_proxy_class" translatable="false"></string>
+    <string name="secondary_display_predictions_class" translatable="false"></string>
 
     <!-- View ID to use for QSB widget -->
     <item type="id" name="qsb_widget" />
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
index a2ab7f9..33b2f55 100644
--- a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncher.java
@@ -29,7 +29,9 @@
 import com.android.launcher3.InvariantDeviceProfile;
 import com.android.launcher3.LauncherAppState;
 import com.android.launcher3.LauncherModel;
+import com.android.launcher3.LauncherSettings;
 import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
 import com.android.launcher3.allapps.ActivityAllAppsContainerView;
 import com.android.launcher3.model.BgDataModel;
 import com.android.launcher3.model.StringCache;
@@ -39,6 +41,8 @@
 import com.android.launcher3.popup.PopupContainerWithArrow;
 import com.android.launcher3.popup.PopupDataProvider;
 import com.android.launcher3.util.ComponentKey;
+import com.android.launcher3.util.IntSet;
+import com.android.launcher3.util.OnboardingPrefs;
 import com.android.launcher3.util.Themes;
 import com.android.launcher3.views.BaseDragLayer;
 
@@ -61,6 +65,9 @@
     private boolean mAppDrawerShown = false;
 
     private StringCache mStringCache;
+    private OnboardingPrefs<?> mOnboardingPrefs;
+    private boolean mBindingItems = false;
+    private SecondaryDisplayPredictions mSecondaryDisplayPredictions;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -69,6 +76,8 @@
         if (getWindow().getDecorView().isAttachedToWindow()) {
             initUi();
         }
+        mOnboardingPrefs = new OnboardingPrefs<>(this, Utilities.getPrefs(this));
+        mSecondaryDisplayPredictions = SecondaryDisplayPredictions.newInstance(this);
     }
 
     @Override
@@ -204,6 +213,7 @@
             mAppDrawerShown = true;
             mAppsView.setVisibility(View.VISIBLE);
             mAppsButton.setVisibility(View.INVISIBLE);
+            mSecondaryDisplayPredictions.updateAppDivider();
         } else {
             mAppDrawerShown = false;
             animator.addListener(new AnimatorListenerAdapter() {
@@ -219,6 +229,26 @@
     }
 
     @Override
+    public OnboardingPrefs<?> getOnboardingPrefs() {
+        return mOnboardingPrefs;
+    }
+
+    @Override
+    public void startBinding() {
+        mBindingItems = true;
+    }
+
+    @Override
+    public boolean isBindingItems() {
+        return mBindingItems;
+    }
+
+    @Override
+    public void finishBindingItems(IntSet pagesBoundFirst) {
+        mBindingItems = false;
+    }
+
+    @Override
     public void bindDeepShortcutMap(HashMap<ComponentKey, Integer> deepShortcutMap) {
         mPopupDataProvider.setDeepShortcutMap(deepShortcutMap);
     }
@@ -230,6 +260,13 @@
     }
 
     @Override
+    public void bindExtraContainerItems(BgDataModel.FixedContainerItems item) {
+        if (item.containerId == LauncherSettings.Favorites.CONTAINER_PREDICTION) {
+            mSecondaryDisplayPredictions.setPredictedApps(item);
+        }
+    }
+
+    @Override
     public StringCache getStringCache() {
         return mStringCache;
     }
@@ -259,7 +296,7 @@
             Intent intent;
             if (item instanceof ItemInfoWithIcon
                     && (((ItemInfoWithIcon) item).runtimeStatusFlags
-                        & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
+                    & ItemInfoWithIcon.FLAG_INSTALL_SESSION_ACTIVE) != 0) {
                 ItemInfoWithIcon appInfo = (ItemInfoWithIcon) item;
                 intent = appInfo.getMarketIntent(this);
             } else {
diff --git a/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictions.java b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictions.java
new file mode 100644
index 0000000..a58916a
--- /dev/null
+++ b/src/com/android/launcher3/secondarydisplay/SecondaryDisplayPredictions.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.secondarydisplay;
+
+import android.content.Context;
+
+import com.android.launcher3.R;
+import com.android.launcher3.model.BgDataModel;
+import com.android.launcher3.util.ResourceBasedOverride;
+
+/**
+ * Exposes Quickstep app prediction row APIs to {@link SecondaryDisplayLauncher}.
+ */
+public class SecondaryDisplayPredictions implements ResourceBasedOverride {
+    /**
+     * Creates a {@link SecondaryDisplayPredictions} instance.
+     */
+    static SecondaryDisplayPredictions newInstance(Context context) {
+        return Overrides.getObject(
+                SecondaryDisplayPredictions.class, context,
+                R.string.secondary_display_predictions_class);
+    }
+
+    /**
+     * Setup/update app divider separating app predictions from All Apps.
+     */
+    void updateAppDivider() {
+    }
+
+    /**
+     * Set predicted apps in top of app drawer.
+     */
+    public void setPredictedApps(BgDataModel.FixedContainerItems item) {
+    }
+}
diff --git a/tests/src/com/android/launcher3/secondarydisplay/SDLauncherTest.java b/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java
similarity index 96%
rename from tests/src/com/android/launcher3/secondarydisplay/SDLauncherTest.java
rename to tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java
index fd86cf1..93fa705 100644
--- a/tests/src/com/android/launcher3/secondarydisplay/SDLauncherTest.java
+++ b/tests/src/com/android/launcher3/secondarydisplay/SecondaryDisplayLauncherTest.java
@@ -32,7 +32,7 @@
  */
 @MediumTest
 @RunWith(AndroidJUnit4.class)
-public class SDLauncherTest {
+public class SecondaryDisplayLauncherTest {
 
     @Before
     public void setUp() {