Merge "Clean up code based on color picker refactor" into main
diff --git a/res/layout/floating_sheet_shape_grid.xml b/res/layout/floating_sheet_shape_grid.xml
index 4e2409b..cd0a709 100644
--- a/res/layout/floating_sheet_shape_grid.xml
+++ b/res/layout/floating_sheet_shape_grid.xml
@@ -47,7 +47,7 @@
             It's critical for any TextViews inside the included layout to have text.
             -->
             <include
-                layout="@layout/shape_option"
+                layout="@layout/shape_option2"
                 android:layout_width="64dp"
                 android:layout_height="64dp"
                 android:visibility="invisible" />
@@ -78,7 +78,7 @@
             It's critical for any TextViews inside the included layout to have text.
             -->
             <include
-                layout="@layout/grid_option"
+                layout="@layout/grid_option2"
                 android:id="@+id/invisible_grid_option"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
diff --git a/res/layout/fragment_grid.xml b/res/layout/fragment_grid.xml
index e77da57..096cb1c 100644
--- a/res/layout/fragment_grid.xml
+++ b/res/layout/fragment_grid.xml
@@ -54,24 +54,23 @@
         android:orientation="vertical"
         android:layout_marginHorizontal="24dp"
         android:layout_marginBottom="28dp"
-        android:background="@drawable/picker_fragment_background"
-        android:paddingBottom="62dp"
-        android:clipChildren="false">
+        android:background="@drawable/picker_fragment_background">
 
         <FrameLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="22dp"
-            android:clipChildren="false">
+            android:paddingVertical="20dp"
+            android:clipChildren="false"
+            android:clipToPadding="false">
 
             <androidx.recyclerview.widget.RecyclerView
                 android:id="@id/options"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="center_horizontal"
-                android:clipToPadding="false"
                 android:paddingHorizontal="16dp"
-                android:clipChildren="false" />
+                android:clipChildren="false"
+                android:clipToPadding="false"/>
 
             <!--
             This is just an invisible placeholder put in place so that the parent keeps its height
diff --git a/res/layout/grid_option.xml b/res/layout/grid_option.xml
index efed018..459584c 100644
--- a/res/layout/grid_option.xml
+++ b/res/layout/grid_option.xml
@@ -47,8 +47,8 @@
 
         <ImageView
             android:id="@id/foreground"
-            android:layout_width="58dp"
-            android:layout_height="58dp"
+            android:layout_width="48dp"
+            android:layout_height="48dp"
             android:layout_gravity="center" />
 
     </FrameLayout>
@@ -64,6 +64,7 @@
         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" />
 
diff --git a/res/layout/shape_option2.xml b/res/layout/shape_option2.xml
new file mode 100644
index 0000000..88d5437
--- /dev/null
+++ b/res/layout/shape_option2.xml
@@ -0,0 +1,36 @@
+<?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.
+  ~
+  -->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="64dp"
+    android:layout_height="64dp"
+    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="36dp"
+        android:layout_height="36dp"
+        android:layout_gravity="center" />
+</FrameLayout>
diff --git a/src/com/android/customization/picker/grid/ui/binder/GridScreenBinder.kt b/src/com/android/customization/picker/grid/ui/binder/GridScreenBinder.kt
index 36d16cd..ae06fff 100644
--- a/src/com/android/customization/picker/grid/ui/binder/GridScreenBinder.kt
+++ b/src/com/android/customization/picker/grid/ui/binder/GridScreenBinder.kt
@@ -36,6 +36,9 @@
 import kotlinx.coroutines.launch
 
 object GridScreenBinder {
+
+    const val GRID_ITEM_SPACING_DP = 20
+
     fun bind(
         view: View,
         viewModel: GridScreenViewModel,
@@ -47,12 +50,8 @@
     ) {
         val optionView: RecyclerView = view.requireViewById(com.android.wallpaper.R.id.options)
         optionView.layoutManager =
-            LinearLayoutManager(
-                view.context,
-                RecyclerView.HORIZONTAL,
-                /* reverseLayout= */ false,
-            )
-        optionView.addItemDecoration(ItemSpacing(ItemSpacing.ITEM_SPACING_DP))
+            LinearLayoutManager(view.context, RecyclerView.HORIZONTAL, /* reverseLayout= */ false)
+        optionView.addItemDecoration(ItemSpacing(GRID_ITEM_SPACING_DP))
         val adapter =
             OptionItemAdapter(
                 layoutResourceId = R.layout.grid_option,
@@ -68,7 +67,7 @@
                 bindIcon = { foregroundView: View, gridIcon: GridIconViewModel ->
                     val imageView = foregroundView as? ImageView
                     imageView?.let { GridIconViewBinder.bind(imageView, gridIcon) }
-                }
+                },
             )
         optionView.adapter = adapter
 
diff --git a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
index 138a253..9cebd27 100644
--- a/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
+++ b/src/com/android/wallpaper/customization/ui/binder/ShapeGridFloatingSheetBinder.kt
@@ -42,9 +42,7 @@
 import com.android.wallpaper.picker.customization.ui.view.FloatingToolbar
 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
 import kotlinx.coroutines.flow.Flow
@@ -90,7 +88,7 @@
 
         val shapeContent = view.requireViewById<View>(R.id.app_shape_container)
         val shapeOptionListAdapter =
-            createShapeOptionItemAdapter(view.context, lifecycleOwner, backgroundDispatcher)
+            createShapeOptionItemAdapter(lifecycleOwner, backgroundDispatcher)
         val shapeOptionList =
             view.requireViewById<RecyclerView>(R.id.shape_options).also {
                 it.initShapeOptionList(view.context, shapeOptionListAdapter)
@@ -209,30 +207,23 @@
     }
 
     private fun createShapeOptionItemAdapter(
-        context: Context,
         lifecycleOwner: LifecycleOwner,
         backgroundDispatcher: CoroutineDispatcher,
-    ): OptionItemAdapter<ShapeIconViewModel> =
-        OptionItemAdapter(
-            layoutResourceId = R.layout.shape_option,
+    ): OptionItemAdapter2<ShapeIconViewModel> =
+        OptionItemAdapter2(
+            layoutResourceId = R.layout.shape_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, shapeIcon: ShapeIconViewModel ->
-                val imageView = foregroundView as? ImageView
+            bindPayload = { view: View, shapeIcon: ShapeIconViewModel ->
+                val imageView = view.findViewById(R.id.foreground) as? ImageView
                 imageView?.let { ShapeIconViewBinder.bind(imageView, shapeIcon) }
+                return@OptionItemAdapter2 null
             },
         )
 
     private fun RecyclerView.initShapeOptionList(
         context: Context,
-        adapter: OptionItemAdapter<ShapeIconViewModel>,
+        adapter: OptionItemAdapter2<ShapeIconViewModel>,
     ) {
         apply {
             this.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
index 1e19e80..85422dd 100644
--- a/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ShapeGridPickerViewModel.kt
@@ -28,7 +28,6 @@
 import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
 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
@@ -105,7 +104,7 @@
             overridingShapeOptionKey ?: selectedShapeKey
         }
 
-    val shapeOptions: Flow<List<OptionItemViewModel<ShapeIconViewModel>>> =
+    val shapeOptions: Flow<List<OptionItemViewModel2<ShapeIconViewModel>>> =
         interactor.shapeOptions
             .filterNotNull()
             .map { shapeOptions -> shapeOptions.map { toShapeOptionItemViewModel(it) } }
@@ -157,7 +156,7 @@
 
     private fun toShapeOptionItemViewModel(
         option: ShapeOptionModel
-    ): OptionItemViewModel<ShapeIconViewModel> {
+    ): OptionItemViewModel2<ShapeIconViewModel> {
         val isSelected =
             previewingShapeKey
                 .map { it == option.key }
@@ -167,7 +166,7 @@
                     initialValue = false,
                 )
 
-        return OptionItemViewModel(
+        return OptionItemViewModel2(
             key = MutableStateFlow(option.key),
             payload = ShapeIconViewModel(option.key, option.path),
             text = Text.Loaded(option.title),
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 71ea0d9..2bca39c 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
@@ -26,7 +26,6 @@
 import com.android.customization.picker.grid.ui.viewmodel.GridIconViewModel
 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
@@ -251,7 +250,7 @@
         }
 
     private fun TestScope.assertShapeItem(
-        optionItem: OptionItemViewModel<ShapeIconViewModel>?,
+        optionItem: OptionItemViewModel2<ShapeIconViewModel>?,
         key: String,
         payload: ShapeIconViewModel?,
         text: Text,