Merge "Make ColorUpdateViewModel ActivityRetainedScoped (2/2)" into main
diff --git a/res/layout/grid_option2.xml b/res/layout/grid_option2.xml
new file mode 100644
index 0000000..437b95b
--- /dev/null
+++ b/res/layout/grid_option2.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2024 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.
+  ~
+  -->
+
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="@dimen/option_item_size"
+    android:layout_height="wrap_content"
+    android:orientation="vertical"
+    android:gravity="center_horizontal"
+    android:clipChildren="false">
+
+    <FrameLayout
+        android:layout_width="@dimen/option_item_size"
+        android:layout_height="@dimen/option_item_size"
+        android:clipChildren="false">
+
+        <com.android.wallpaper.picker.option.ui.view.OptionItemBackground
+            android:id="@id/background"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:background="@drawable/option_item_background"
+            android:importantForAccessibility="no" />
+
+        <ImageView
+            android:id="@id/foreground"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
+            android:layout_gravity="center" />
+
+    </FrameLayout>
+
+    <View
+        android:layout_width="0dp"
+        android:layout_height="8dp" />
+
+    <TextView
+        android:id="@id/text"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:textColor="@color/system_on_surface"
+        android:singleLine="true"
+        android:ellipsize="end"
+        android:textSize="12sp"
+        android:text="Placeholder for stable size calculation, please do not remove."
+        tools:ignore="HardcodedText" />
+
+</LinearLayout>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 0c36753..4f1062f 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -189,6 +189,7 @@
     <dimen name="floating_sheet_tab_clock_font_toolbar_top_margin">16dp</dimen>
     <dimen name="floating_sheet_tab_clock_font_toolbar_bottom_margin">8dp</dimen>
     <dimen name="floating_sheet_list_item_horizontal_space">4dp</dimen>
+    <dimen name="floating_sheet_grid_list_item_horizontal_space">10dp</dimen>
     <dimen name="floating_sheet_list_item_vertical_space">4dp</dimen>
     <dimen name="floating_sheet_clock_style_option_list_margin_bottom">8dp</dimen>
     <dimen name="floating_sheet_clock_style_option_width">80dp</dimen>
diff --git a/src/com/android/customization/model/color/ColorCustomizationManager.java b/src/com/android/customization/model/color/ColorCustomizationManager.java
index 9acbc4f..61a7967 100644
--- a/src/com/android/customization/model/color/ColorCustomizationManager.java
+++ b/src/com/android/customization/model/color/ColorCustomizationManager.java
@@ -48,6 +48,7 @@
 import com.android.customization.model.color.ColorOptionsProvider.ColorSource;
 import com.android.customization.model.theme.OverlayManagerCompat;
 import com.android.customization.module.logging.ThemesUserEventLogger;
+import com.android.systemui.monet.Style;
 import com.android.themepicker.R;
 
 import org.json.JSONArray;
@@ -164,7 +165,7 @@
                 overlaysJson.put(OVERLAY_COLOR_SOURCE, colorOption.getSource());
                 overlaysJson.put(OVERLAY_COLOR_INDEX, String.valueOf(colorOption.getIndex()));
                 overlaysJson.put(OVERLAY_THEME_STYLE,
-                        String.valueOf(colorOption.getStyle().toString()));
+                        String.valueOf(Style.toString(colorOption.getStyle())));
 
                 // OVERLAY_COLOR_BOTH is only for wallpaper color case, not preset.
                 if (!COLOR_SOURCE_PRESET.equals(colorOption.getSource())) {
diff --git a/src/com/android/customization/model/color/ColorOption.java b/src/com/android/customization/model/color/ColorOption.java
index 18414a4..a62756f 100644
--- a/src/com/android/customization/model/color/ColorOption.java
+++ b/src/com/android/customization/model/color/ColorOption.java
@@ -39,6 +39,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.stream.Collectors;
 
@@ -56,13 +57,14 @@
     protected final Map<String, String> mPackagesByCategory;
     private final String mTitle;
     private final boolean mIsDefault;
-    private final Style mStyle;
+    @Style.Type
+    private final Integer mStyle;
     private final int mIndex;
     private CharSequence mContentDescription;
     private final @ColorInt int mSeedColor;
 
     protected ColorOption(String title, Map<String, String> overlayPackages, boolean isDefault,
-            int seedColor, Style style, int index) {
+            int seedColor, @Style.Type Integer style, int index) {
         mTitle = title;
         mIsDefault = isDefault;
         mSeedColor = seedColor;
@@ -82,9 +84,9 @@
 
         String currentStyle = colorManager.getCurrentStyle();
         if (TextUtils.isEmpty(currentStyle)) {
-            currentStyle = Style.TONAL_SPOT.toString();
+            currentStyle = Style.toString(Style.TONAL_SPOT);
         }
-        boolean isCurrentStyle = TextUtils.equals(getStyle().toString(), currentStyle);
+        boolean isCurrentStyle = TextUtils.equals(Style.toString(getStyle()), currentStyle);
 
         if (mIsDefault) {
             String serializedOverlays = colorManager.getStoredOverlays();
@@ -116,7 +118,7 @@
         if (other == null) {
             return false;
         }
-        if (mStyle != other.getStyle()) {
+        if (!Objects.equals(mStyle, other.getStyle())) {
             return false;
         }
         String thisSerializedPackages = getSerializedPackages();
@@ -225,7 +227,8 @@
     /**
      * @return the style of this color option
      */
-    public Style getStyle() {
+    @Style.Type
+    public Integer getStyle() {
         return mStyle;
     }
 
diff --git a/src/com/android/customization/model/color/ColorOptionImpl.kt b/src/com/android/customization/model/color/ColorOptionImpl.kt
index 3b8fbc8..d8d562d 100644
--- a/src/com/android/customization/model/color/ColorOptionImpl.kt
+++ b/src/com/android/customization/model/color/ColorOptionImpl.kt
@@ -34,7 +34,7 @@
     isDefault: Boolean,
     private val source: String?,
     seedColor: Int,
-    style: Style,
+    @Style.Type style: Int,
     index: Int,
     private val previewInfo: PreviewInfo,
     val type: ColorType,
@@ -77,7 +77,7 @@
         }
     }
 
-    override fun getStyleForLogging(): Int = style.toString().hashCode()
+    override fun getStyleForLogging(): Int = Style.toString(style).hashCode()
 
     class Builder {
         var title: String? = null
@@ -89,7 +89,7 @@
         @ColorSource var source: String? = null
         var isDefault = false
         @ColorInt var seedColor = 0
-        var style = Style.TONAL_SPOT
+        @Style.Type var style = Style.TONAL_SPOT
         var index = 0
         var packages: MutableMap<String, String?> = HashMap()
         var type = ColorType.WALLPAPER_COLOR
diff --git a/src/com/android/customization/model/color/ColorProvider.kt b/src/com/android/customization/model/color/ColorProvider.kt
index fb9fcfc..74da5c2 100644
--- a/src/com/android/customization/model/color/ColorProvider.kt
+++ b/src/com/android/customization/model/color/ColorProvider.kt
@@ -67,6 +67,7 @@
     private var loaderJob: Job? = null
     private val monetEnabled = ColorUtils.isMonetEnabled(context)
     // TODO(b/202145216): Use style method to fetch the list of style.
+    @Style.Type
     private var styleList =
         if (themeStyleEnabled)
             arrayOf(Style.TONAL_SPOT, Style.SPRITZ, Style.VIBRANT, Style.EXPRESSIVE)
@@ -338,6 +339,7 @@
                         } catch (e: Resources.NotFoundException) {
                             null
                         }
+                    @Style.Type
                     val style =
                         try {
                             if (styleName != null) Style.valueOf(styleName) else Style.TONAL_SPOT
@@ -374,7 +376,7 @@
     private fun buildPreset(
         bundleName: String,
         index: Int,
-        style: Style? = null,
+        @Style.Type style: Int? = null,
         type: ColorType = ColorType.PRESET_COLOR,
     ): ColorOptionImpl {
         val builder = ColorOptionImpl.Builder()
diff --git a/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt b/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt
index c426f9d..ee0f619 100644
--- a/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt
+++ b/src/com/android/customization/model/color/ThemedWallpaperColorResources.kt
@@ -38,11 +38,7 @@
     override suspend fun apply(context: Context, callback: () -> Unit) {
         withContext(Dispatchers.IO) {
             val wallpaperColorScheme =
-                ColorScheme(
-                    wallpaperColors,
-                    false,
-                    fetchThemeStyleFromSetting(),
-                )
+                ColorScheme(wallpaperColors, false, fetchThemeStyleFromSetting())
             with<ColorScheme, Unit>(wallpaperColorScheme) {
                 addOverlayColor(neutral1, R.color.system_neutral1_10)
                 addOverlayColor(neutral2, R.color.system_neutral2_10)
@@ -55,7 +51,8 @@
         }
     }
 
-    private suspend fun fetchThemeStyleFromSetting(): Style {
+    @Style.Type
+    private suspend fun fetchThemeStyleFromSetting(): Int {
         val overlayPackageJson =
             secureSettingsRepository.getString(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES)
         return if (!overlayPackageJson.isNullOrEmpty()) {
diff --git a/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt b/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
index 3f120ce..b426516 100644
--- a/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
+++ b/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
@@ -161,7 +161,7 @@
         return builder.build()
     }
 
-    fun buildPresetOption(style: Style, seedColor: Int): ColorOptionImpl {
+    fun buildPresetOption(@Style.Type style: Int, seedColor: Int): ColorOptionImpl {
         val builder = ColorOptionImpl.Builder()
         builder.lightColors =
             intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT)
@@ -197,7 +197,11 @@
         return builder.build()
     }
 
-    fun buildWallpaperOption(source: String, style: Style, seedColor: Int): ColorOptionImpl {
+    fun buildWallpaperOption(
+        source: String,
+        @Style.Type style: Int,
+        seedColor: Int,
+    ): ColorOptionImpl {
         val builder = ColorOptionImpl.Builder()
         builder.lightColors =
             intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT)
diff --git a/src/com/android/customization/picker/color/data/util/MaterialColorsGenerator.kt b/src/com/android/customization/picker/color/data/util/MaterialColorsGenerator.kt
index a921365..a1cc8ff 100644
--- a/src/com/android/customization/picker/color/data/util/MaterialColorsGenerator.kt
+++ b/src/com/android/customization/picker/color/data/util/MaterialColorsGenerator.kt
@@ -70,7 +70,7 @@
      *
      * @return a list of color resource IDs and a corresponding list of their color values
      */
-    fun generate(colorSeed: Int, style: Style): Pair<IntArray, IntArray> {
+    fun generate(colorSeed: Int, @Style.Type style: Int): Pair<IntArray, IntArray> {
         val isDarkMode =
             (applicationContext.resources.configuration.uiMode and
                 Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
@@ -94,7 +94,8 @@
         )
     }
 
-    private suspend fun fetchThemeStyleFromSetting(): Style {
+    @Style.Type
+    private suspend fun fetchThemeStyleFromSetting(): Int {
         val overlayPackageJson =
             secureSettingsRepository.getString(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES)
         return if (!overlayPackageJson.isNullOrEmpty()) {
diff --git a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
index 5f292bd..138a253 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
@@ -43,6 +43,7 @@
 import com.android.wallpaper.picker.customization.ui.view.adapter.FloatingToolbarTabAdapter
 import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel
 import com.android.wallpaper.picker.option.ui.adapter.OptionItemAdapter
+import com.android.wallpaper.picker.option.ui.adapter.OptionItemAdapter2
 import com.android.wallpaper.picker.option.ui.binder.OptionItemBinder
 import java.lang.ref.WeakReference
 import kotlinx.coroutines.CoroutineDispatcher
@@ -97,7 +98,7 @@
 
         val gridContent = view.requireViewById<View>(R.id.app_grid_container)
         val gridOptionListAdapter =
-            createGridOptionItemAdapter(view.context, lifecycleOwner, backgroundDispatcher)
+            createGridOptionItemAdapter(lifecycleOwner, backgroundDispatcher)
         val gridOptionList =
             view.requireViewById<RecyclerView>(R.id.grid_options).also {
                 it.initGridOptionList(view.context, gridOptionListAdapter)
@@ -243,8 +244,7 @@
                         ),
                     itemHorizontalSpacePx =
                         context.resources.getDimensionPixelSize(
-                            com.android.themepicker.R.dimen
-                                .floating_sheet_list_item_horizontal_space
+                            R.dimen.floating_sheet_list_item_horizontal_space
                         ),
                 )
             )
@@ -253,30 +253,23 @@
     }
 
     private fun createGridOptionItemAdapter(
-        context: Context,
         lifecycleOwner: LifecycleOwner,
         backgroundDispatcher: CoroutineDispatcher,
-    ): OptionItemAdapter<GridIconViewModel> =
-        OptionItemAdapter(
-            layoutResourceId = R.layout.grid_option,
+    ): OptionItemAdapter2<GridIconViewModel> =
+        OptionItemAdapter2(
+            layoutResourceId = R.layout.grid_option2,
             lifecycleOwner = lifecycleOwner,
             backgroundDispatcher = backgroundDispatcher,
-            foregroundTintSpec =
-                OptionItemBinder.TintSpec(
-                    selectedColor =
-                        context.getColor(com.android.wallpaper.R.color.system_on_surface),
-                    unselectedColor =
-                        context.getColor(com.android.wallpaper.R.color.system_on_surface),
-                ),
-            bindIcon = { foregroundView: View, gridIcon: GridIconViewModel ->
-                val imageView = foregroundView as? ImageView
+            bindPayload = { view: View, gridIcon: GridIconViewModel ->
+                val imageView = view.findViewById(R.id.foreground) as? ImageView
                 imageView?.let { GridIconViewBinder.bind(imageView, gridIcon) }
+                return@OptionItemAdapter2 null
             },
         )
 
     private fun RecyclerView.initGridOptionList(
         context: Context,
-        adapter: OptionItemAdapter<GridIconViewModel>,
+        adapter: OptionItemAdapter2<GridIconViewModel>,
     ) {
         apply {
             this.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
@@ -288,8 +281,7 @@
                         ),
                     itemHorizontalSpacePx =
                         context.resources.getDimensionPixelSize(
-                            com.android.themepicker.R.dimen
-                                .floating_sheet_list_item_horizontal_space
+                            R.dimen.floating_sheet_grid_list_item_horizontal_space
                         ),
                 )
             )
diff --git a/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
index eaed4e5..46d0346 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
@@ -52,7 +52,6 @@
 import javax.inject.Singleton
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.combine
-import kotlinx.coroutines.flow.filterNotNull
 import kotlinx.coroutines.launch
 
 @Singleton
@@ -259,7 +258,7 @@
             lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                 launch {
                     combine(
-                            clockPickerViewModel.previewingClock.filterNotNull(),
+                            clockPickerViewModel.previewingClock,
                             clockPickerViewModel.previewingClockSize,
                         ) { clock, size ->
                             clock to size
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ClockPickerViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ClockPickerViewModel.kt
index 6ca773b..2a1a8c9 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ClockPickerViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ClockPickerViewModel.kt
@@ -57,6 +57,7 @@
 import kotlinx.coroutines.flow.flowOn
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.mapLatest
+import kotlinx.coroutines.flow.shareIn
 import kotlinx.coroutines.flow.stateIn
 
 /** View model for the clock customization screen. */
@@ -120,8 +121,9 @@
     val selectedClock = clockPickerInteractor.selectedClock
     val previewingClock =
         combine(overridingClock, selectedClock) { overridingClock, selectedClock ->
-            overridingClock ?: selectedClock
-        }
+                (overridingClock ?: selectedClock)
+            }
+            .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1)
 
     data class ClockStyleModel(val thumbnail: Drawable, val showEditButton: StateFlow<Boolean>)
 
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
index 7f3c4cb..1e19e80 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
@@ -29,6 +29,7 @@
 import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
 import com.android.wallpaper.picker.customization.ui.viewmodel.FloatingToolbarTabViewModel
 import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel
+import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel2
 import dagger.assisted.Assisted
 import dagger.assisted.AssistedFactory
 import dagger.assisted.AssistedInject
@@ -126,7 +127,7 @@
             overridingGridOptionKey ?: selectedGridOption.key.value
         }
 
-    val gridOptions: Flow<List<OptionItemViewModel<GridIconViewModel>>> =
+    val gridOptions: Flow<List<OptionItemViewModel2<GridIconViewModel>>> =
         interactor.gridOptions
             .filterNotNull()
             .map { gridOptions -> gridOptions.map { toGridOptionItemViewModel(it) } }
@@ -184,7 +185,7 @@
 
     private fun toGridOptionItemViewModel(
         option: GridOptionModel
-    ): OptionItemViewModel<GridIconViewModel> {
+    ): OptionItemViewModel2<GridIconViewModel> {
         val iconShapePath =
             context.resources.getString(
                 Resources.getSystem()
@@ -203,7 +204,7 @@
                     initialValue = false,
                 )
 
-        return OptionItemViewModel(
+        return OptionItemViewModel2(
             key = MutableStateFlow(option.key),
             payload =
                 GridIconViewModel(columns = option.cols, rows = option.rows, path = iconShapePath),
diff --git a/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt b/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
index cb6057d..5e5bc1f 100644
--- a/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
+++ b/src/com/android/wallpaper/picker/common/preview/ui/binder/ThemePickerWorkspaceCallbackBinder.kt
@@ -25,13 +25,21 @@
 import androidx.lifecycle.repeatOnLifecycle
 import com.android.customization.model.grid.DefaultShapeGridManager.Companion.COL_GRID_NAME
 import com.android.customization.model.grid.DefaultShapeGridManager.Companion.COL_SHAPE_KEY
+import com.android.customization.picker.clock.shared.ClockSize
+import com.android.customization.picker.clock.ui.view.ClockViewFactory
 import com.android.customization.picker.color.data.util.MaterialColorsGenerator
 import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_END
 import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.CLOCK_SIZE_DYNAMIC
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.CLOCK_SIZE_SMALL
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_CLOCK_SIZE
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_HIDE_SMART_SPACE
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_QUICK_AFFORDANCE_ID
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_SLOT_ID
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_DEFAULT_PREVIEW
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_HIDE_SMART_SPACE
+import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_PREVIEW_CLOCK_SIZE
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_SLOT_SELECTED
 import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES
@@ -60,6 +68,7 @@
         colorUpdateViewModel: ColorUpdateViewModel,
         screen: Screen,
         lifecycleOwner: LifecycleOwner,
+        clockViewFactory: ClockViewFactory,
     ) {
         defaultWorkspaceCallbackBinder.bind(
             workspaceCallback = workspaceCallback,
@@ -67,6 +76,7 @@
             colorUpdateViewModel = colorUpdateViewModel,
             screen = screen,
             lifecycleOwner = lifecycleOwner,
+            clockViewFactory = clockViewFactory,
         )
 
         if (viewModel !is ThemePickerCustomizationOptionsViewModel) {
@@ -135,6 +145,48 @@
                                     }
                                 }
                         }
+
+                        launch {
+                            combine(
+                                    viewModel.clockPickerViewModel.previewingClock,
+                                    viewModel.clockPickerViewModel.previewingClockSize,
+                                    ::Pair,
+                                )
+                                .collect { (previewingClock, previewingClockSize) ->
+                                    val hideSmartspace =
+                                        clockViewFactory
+                                            .getController(previewingClock.clockId)
+                                            .let {
+                                                when (previewingClockSize) {
+                                                    ClockSize.DYNAMIC ->
+                                                        it.largeClock.config
+                                                            .hasCustomWeatherDataDisplay
+                                                    ClockSize.SMALL ->
+                                                        it.smallClock.config
+                                                            .hasCustomWeatherDataDisplay
+                                                }
+                                            }
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_HIDE_SMART_SPACE,
+                                        Bundle().apply {
+                                            putBoolean(KEY_HIDE_SMART_SPACE, hideSmartspace)
+                                        },
+                                    )
+
+                                    workspaceCallback.sendMessage(
+                                        MESSAGE_ID_PREVIEW_CLOCK_SIZE,
+                                        Bundle().apply {
+                                            putString(
+                                                KEY_CLOCK_SIZE,
+                                                when (previewingClockSize) {
+                                                    ClockSize.DYNAMIC -> CLOCK_SIZE_DYNAMIC
+                                                    ClockSize.SMALL -> CLOCK_SIZE_SMALL
+                                                },
+                                            )
+                                        },
+                                    )
+                                }
+                        }
                     }
                 }
             Screen.HOME_SCREEN ->
diff --git a/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt b/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt
index 98a1973..13f58a5 100644
--- a/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt
+++ b/tests/robotests/src/com/android/customization/model/color/ColorCustomizationManagerTest.kt
@@ -71,7 +71,7 @@
     @Test
     fun testParseSettings() {
         val source = COLOR_SOURCE_HOME
-        val style = Style.SPRITZ
+        @Style.Type val style = Style.SPRITZ
         val someColor = "aabbcc"
         val someOtherColor = "bbccdd"
         val settings =
@@ -79,7 +79,7 @@
                 OVERLAY_CATEGORY_SYSTEM_PALETTE to someColor,
                 OVERLAY_CATEGORY_COLOR to someOtherColor,
                 OVERLAY_COLOR_SOURCE to source,
-                OVERLAY_THEME_STYLE to style.toString(),
+                OVERLAY_THEME_STYLE to Style.toString(style),
                 ColorOption.TIMESTAMP_FIELD to "12345",
             )
         val json = JSONObject(settings).toString()
@@ -87,7 +87,7 @@
         manager.parseSettings(json)
 
         assertThat(manager.currentColorSource).isEqualTo(source)
-        assertThat(manager.currentStyle).isEqualTo(style.toString())
+        assertThat(manager.currentStyle).isEqualTo(Style.toString(style))
         assertThat(manager.currentOverlays.size).isEqualTo(2)
         assertThat(manager.currentOverlays[OVERLAY_CATEGORY_COLOR]).isEqualTo(someOtherColor)
         assertThat(manager.currentOverlays[OVERLAY_CATEGORY_SYSTEM_PALETTE]).isEqualTo(someColor)
diff --git a/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt b/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt
index ed04d14..75d10ca 100644
--- a/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt
+++ b/tests/robotests/src/com/android/customization/model/color/ColorOptionTest.kt
@@ -72,7 +72,7 @@
         testColorOptionStyle(Style.EXPRESSIVE)
     }
 
-    private fun testColorOptionStyle(style: Style) {
+    private fun testColorOptionStyle(@Style.Type style: Int) {
         val colorOption: ColorOption =
             ColorOptionImpl(
                 "fake color",
diff --git a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt
index 50602ad..b39a564 100644
--- a/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt
+++ b/tests/robotests/src/com/android/customization/model/picker/color/ui/viewmodel/ColorPickerViewModelTest.kt
@@ -147,7 +147,8 @@
 
             assertThat(logger.themeColorSource)
                 .isEqualTo(StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER)
-            assertThat(logger.themeColorStyle).isEqualTo(Style.EXPRESSIVE.toString().hashCode())
+            assertThat(logger.themeColorStyle)
+                .isEqualTo(Style.toString(Style.EXPRESSIVE).hashCode())
             assertThat(logger.themeSeedColor).isEqualTo(121212)
         }
 
@@ -177,7 +178,8 @@
             advanceUntilIdle()
 
             assertThat(logger.themeColorSource).isEqualTo(StyleEnums.COLOR_SOURCE_PRESET_COLOR)
-            assertThat(logger.themeColorStyle).isEqualTo(Style.FRUIT_SALAD.toString().hashCode())
+            assertThat(logger.themeColorStyle)
+                .isEqualTo(Style.toString(Style.FRUIT_SALAD).hashCode())
             assertThat(logger.themeSeedColor).isEqualTo(-54321)
         }
 
diff --git a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ColorPickerViewModel2Test.kt b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ColorPickerViewModel2Test.kt
index 9827a56..07c3a16 100644
--- a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ColorPickerViewModel2Test.kt
+++ b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ColorPickerViewModel2Test.kt
@@ -151,7 +151,8 @@
 
             assertThat(logger.themeColorSource)
                 .isEqualTo(StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER)
-            assertThat(logger.themeColorStyle).isEqualTo(Style.EXPRESSIVE.toString().hashCode())
+            assertThat(logger.themeColorStyle)
+                .isEqualTo(Style.toString(Style.EXPRESSIVE).hashCode())
             assertThat(logger.themeSeedColor).isEqualTo(121212)
         }
 
@@ -182,7 +183,8 @@
             applySelectedColorOption()
 
             assertThat(logger.themeColorSource).isEqualTo(StyleEnums.COLOR_SOURCE_PRESET_COLOR)
-            assertThat(logger.themeColorStyle).isEqualTo(Style.FRUIT_SALAD.toString().hashCode())
+            assertThat(logger.themeColorStyle)
+                .isEqualTo(Style.toString(Style.FRUIT_SALAD).hashCode())
             assertThat(logger.themeSeedColor).isEqualTo(-54321)
         }
 
diff --git a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
index c99acca..71ea0d9 100644
--- a/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
+++ b/tests/robotests/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModelTest.kt
@@ -27,6 +27,7 @@
 import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
 import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
 import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel
+import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel2
 import com.android.wallpaper.testing.collectLastValue
 import com.google.common.truth.Truth.assertThat
 import dagger.hilt.android.qualifiers.ApplicationContext
@@ -159,7 +160,7 @@
         testScope.runTest {
             val selectedGridOption = collectLastValue(underTest.selectedGridOption)
 
-            assertOptionItem(
+            assertGridItem(
                 optionItem = selectedGridOption(),
                 key = "normal",
                 payload = GridIconViewModel(5, 5, iconShapePath),
@@ -183,7 +184,7 @@
             onPracticalOptionClick()?.invoke()
             onApply()?.invoke()
 
-            assertOptionItem(
+            assertGridItem(
                 optionItem = selectedGridOption(),
                 key = "practical",
                 payload = GridIconViewModel(4, 5, iconShapePath),
@@ -199,7 +200,7 @@
         testScope.runTest {
             val optionItems = collectLastValue(underTest.gridOptions)
 
-            assertOptionItem(
+            assertGridItem(
                 optionItem = optionItems()?.get(0),
                 key = "normal",
                 payload = GridIconViewModel(5, 5, iconShapePath),
@@ -208,7 +209,7 @@
                 isSelected = true,
                 isEnabled = true,
             )
-            assertOptionItem(
+            assertGridItem(
                 optionItem = optionItems()?.get(1),
                 key = "practical",
                 payload = GridIconViewModel(4, 5, iconShapePath),
@@ -229,7 +230,7 @@
 
             onPracticalOptionClick()?.invoke()
 
-            assertOptionItem(
+            assertGridItem(
                 optionItem = optionItems()?.get(0),
                 key = "normal",
                 payload = GridIconViewModel(5, 5, iconShapePath),
@@ -238,7 +239,7 @@
                 isSelected = false,
                 isEnabled = true,
             )
-            assertOptionItem(
+            assertGridItem(
                 optionItem = optionItems()?.get(1),
                 key = "practical",
                 payload = GridIconViewModel(4, 5, iconShapePath),
@@ -267,8 +268,8 @@
         assertThat(optionItem.isEnabled).isEqualTo(isEnabled)
     }
 
-    private fun TestScope.assertOptionItem(
-        optionItem: OptionItemViewModel<GridIconViewModel>?,
+    private fun TestScope.assertGridItem(
+        optionItem: OptionItemViewModel2<GridIconViewModel>?,
         key: String,
         payload: GridIconViewModel?,
         text: Text,