Move customization options to proper projects (3/3)

Move the customization options to correspondent projects, so that
WallpaperPicker2 only has wallpaper customization
ThemePicker has clock, color, customiztion etc.
WallpaperPickerGoogle has all customization options

Test: Manually tested it works as expected
Bug: 343300705
Flag: com.android.wallpaper.new_picker_ui_flag
Change-Id: I5f68b6afe3e3e99aea21c5866fbe187db7e1431a
diff --git a/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
new file mode 100644
index 0000000..28acc43
--- /dev/null
+++ b/src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package com.android.wallpaper.customization.ui.binder
+
+import android.view.View
+import android.widget.TextView
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.LifecycleOwner
+import androidx.lifecycle.lifecycleScope
+import androidx.lifecycle.repeatOnLifecycle
+import com.android.wallpaper.R
+import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel
+import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
+import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder
+import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
+import javax.inject.Inject
+import javax.inject.Singleton
+import kotlinx.coroutines.launch
+
+@Singleton
+class ThemePickerCustomizationOptionsBinder
+@Inject
+constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationOptionsBinder) :
+    CustomizationOptionsBinder {
+
+    override fun bind(
+        view: View,
+        viewModel: CustomizationOptionsViewModel,
+        lifecycleOwner: LifecycleOwner
+    ) {
+        defaultCustomizationOptionsBinder.bind(view, viewModel, lifecycleOwner)
+
+        val optionClock = view.requireViewById<TextView>(R.id.option_clock)
+        val optionShortcut = view.requireViewById<TextView>(R.id.option_shortcut)
+        viewModel as ThemePickerCustomizationOptionsViewModel
+
+        lifecycleOwner.lifecycleScope.launch {
+            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
+                launch {
+                    viewModel.onCustomizeClockClicked.collect {
+                        optionClock.setOnClickListener { _ -> it?.invoke() }
+                    }
+                }
+
+                launch {
+                    viewModel.onCustomizeShortcutClicked.collect {
+                        optionShortcut.setOnClickListener { _ -> it?.invoke() }
+                    }
+                }
+            }
+        }
+    }
+}
diff --git a/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt b/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt
new file mode 100644
index 0000000..5340f52
--- /dev/null
+++ b/src/com/android/wallpaper/customization/ui/util/ThemePickerCustomizationOptionUtil.kt
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+package com.android.wallpaper.customization.ui.util
+
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.FrameLayout
+import com.android.wallpaper.R
+import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil
+import com.android.wallpaper.picker.customization.ui.util.DefaultCustomizationOptionUtil
+import dagger.hilt.android.scopes.ActivityScoped
+import javax.inject.Inject
+
+@ActivityScoped
+class ThemePickerCustomizationOptionUtil
+@Inject
+constructor(private val defaultCustomizationOptionUtil: DefaultCustomizationOptionUtil) :
+    CustomizationOptionUtil {
+
+    enum class ThemePickerLockCustomizationOption : CustomizationOptionUtil.CustomizationOption {
+        CLOCK,
+        SHORTCUTS,
+        SHOW_NOTIFICATIONS,
+        MORE_LOCK_SCREEN_SETTINGS,
+    }
+
+    enum class ThemePickerHomeCustomizationOption : CustomizationOptionUtil.CustomizationOption {
+        COLORS,
+        APP_GRID,
+        APP_SHAPE,
+        THEMED_ICONS,
+    }
+
+    private var viewMap: Map<CustomizationOptionUtil.CustomizationOption, View>? = null
+
+    override fun initBottomSheetContent(
+        bottomSheetContainer: FrameLayout,
+        layoutInflater: LayoutInflater
+    ) {
+        defaultCustomizationOptionUtil.initBottomSheetContent(bottomSheetContainer, layoutInflater)
+        viewMap = buildMap {
+            put(
+                ThemePickerLockCustomizationOption.CLOCK,
+                createCustomizationPickerBottomSheetView(
+                        ThemePickerLockCustomizationOption.CLOCK,
+                        bottomSheetContainer,
+                        layoutInflater,
+                    )
+                    .also { bottomSheetContainer.addView(it) }
+            )
+            put(
+                ThemePickerLockCustomizationOption.SHORTCUTS,
+                createCustomizationPickerBottomSheetView(
+                        ThemePickerLockCustomizationOption.SHORTCUTS,
+                        bottomSheetContainer,
+                        layoutInflater,
+                    )
+                    .also { bottomSheetContainer.addView(it) }
+            )
+        }
+    }
+
+    override fun getBottomSheetContent(option: CustomizationOptionUtil.CustomizationOption): View? {
+        return defaultCustomizationOptionUtil.getBottomSheetContent(option) ?: viewMap?.get(option)
+    }
+
+    override fun onDestroy() {
+        viewMap = null
+    }
+
+    private fun createCustomizationPickerBottomSheetView(
+        option: ThemePickerLockCustomizationOption,
+        bottomSheetContainer: FrameLayout,
+        layoutInflater: LayoutInflater,
+    ): View =
+        when (option) {
+            ThemePickerLockCustomizationOption.CLOCK -> R.layout.bottom_sheet_clock
+            ThemePickerLockCustomizationOption.SHORTCUTS -> R.layout.bottom_sheet_shortcut
+            else ->
+                throw IllegalStateException(
+                    "Customization option $option does not have a bottom sheet view"
+                )
+        }.let { layoutInflater.inflate(it, bottomSheetContainer, false) }
+}
diff --git a/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
new file mode 100644
index 0000000..cc909b5
--- /dev/null
+++ b/src/com/android/wallpaper/customization/ui/viewmodel/ThemePickerCustomizationOptionsViewModel.kt
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+package com.android.wallpaper.customization.ui.viewmodel
+
+import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil
+import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
+import com.android.wallpaper.picker.customization.ui.viewmodel.DefaultCustomizationOptionsViewModel
+import dagger.hilt.android.scopes.ViewModelScoped
+import javax.inject.Inject
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.map
+
+@ViewModelScoped
+class ThemePickerCustomizationOptionsViewModel
+@Inject
+constructor(
+    private val defaultCustomizationOptionsViewModel: DefaultCustomizationOptionsViewModel
+) : CustomizationOptionsViewModel {
+
+    override val selectedOption = defaultCustomizationOptionsViewModel.selectedOption
+
+    override fun deselectOption(): Boolean = defaultCustomizationOptionsViewModel.deselectOption()
+
+    val onCustomizeClockClicked: Flow<(() -> Unit)?> =
+        selectedOption.map {
+            if (it == null) {
+                {
+                    defaultCustomizationOptionsViewModel.selectOption(
+                        ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption.CLOCK
+                    )
+                }
+            } else {
+                null
+            }
+        }
+
+    val onCustomizeShortcutClicked: Flow<(() -> Unit)?> =
+        selectedOption.map {
+            if (it == null) {
+                {
+                    defaultCustomizationOptionsViewModel.selectOption(
+                        ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption
+                            .SHORTCUTS
+                    )
+                }
+            } else {
+                null
+            }
+        }
+}
diff --git a/src_override/com/android/wallpaper/modules/ThemePickerActivityModule.kt b/src_override/com/android/wallpaper/modules/ThemePickerActivityModule.kt
new file mode 100644
index 0000000..90a0e3b
--- /dev/null
+++ b/src_override/com/android/wallpaper/modules/ThemePickerActivityModule.kt
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package com.android.wallpaper.modules
+
+import com.android.wallpaper.customization.ui.util.ThemePickerCustomizationOptionUtil
+import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil
+import dagger.Binds
+import dagger.Module
+import dagger.hilt.InstallIn
+import dagger.hilt.android.components.ActivityComponent
+import dagger.hilt.android.scopes.ActivityScoped
+
+@Module
+@InstallIn(ActivityComponent::class)
+abstract class ThemePickerActivityModule {
+
+    @Binds
+    @ActivityScoped
+    abstract fun bindCustomizationOptionUtil(
+        impl: ThemePickerCustomizationOptionUtil
+    ): CustomizationOptionUtil
+}
diff --git a/src_override/com/android/wallpaper/modules/ThemePickerAppModule.kt b/src_override/com/android/wallpaper/modules/ThemePickerAppModule.kt
index 517075e..ab1541c 100644
--- a/src_override/com/android/wallpaper/modules/ThemePickerAppModule.kt
+++ b/src_override/com/android/wallpaper/modules/ThemePickerAppModule.kt
@@ -23,10 +23,12 @@
 import com.android.customization.module.ThemePickerInjector
 import com.android.customization.module.logging.ThemesUserEventLogger
 import com.android.customization.module.logging.ThemesUserEventLoggerImpl
+import com.android.wallpaper.customization.ui.binder.ThemePickerCustomizationOptionsBinder
 import com.android.wallpaper.module.DefaultPartnerProvider
 import com.android.wallpaper.module.PartnerProvider
 import com.android.wallpaper.module.WallpaperPreferences
 import com.android.wallpaper.module.logging.UserEventLogger
+import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
 import com.android.wallpaper.picker.preview.data.util.DefaultLiveWallpaperDownloader
 import com.android.wallpaper.picker.preview.data.util.LiveWallpaperDownloader
 import com.android.wallpaper.picker.preview.ui.util.DefaultImageEffectDialogUtil
@@ -76,6 +78,12 @@
         impl: DefaultImageEffectDialogUtil
     ): ImageEffectDialogUtil
 
+    @Binds
+    @Singleton
+    abstract fun bindCustomizationOptionsBinder(
+        impl: ThemePickerCustomizationOptionsBinder
+    ): CustomizationOptionsBinder
+
     companion object {
         @Provides
         @Singleton
diff --git a/src_override/com/android/wallpaper/modules/ThemePickerViewModelModule.kt b/src_override/com/android/wallpaper/modules/ThemePickerViewModelModule.kt
new file mode 100644
index 0000000..3a80437
--- /dev/null
+++ b/src_override/com/android/wallpaper/modules/ThemePickerViewModelModule.kt
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package com.android.wallpaper.modules
+
+import com.android.wallpaper.customization.ui.viewmodel.ThemePickerCustomizationOptionsViewModel
+import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
+import dagger.Binds
+import dagger.Module
+import dagger.hilt.InstallIn
+import dagger.hilt.android.components.ViewModelComponent
+import dagger.hilt.android.scopes.ViewModelScoped
+
+@Module
+@InstallIn(ViewModelComponent::class)
+abstract class ThemePickerViewModelModule {
+
+    @Binds
+    @ViewModelScoped
+    abstract fun bindCustomizationOptionsViewModel(
+        impl: ThemePickerCustomizationOptionsViewModel
+    ): CustomizationOptionsViewModel
+}
diff --git a/tests/module/src/com/android/wallpaper/ThemePickerTestModule.kt b/tests/module/src/com/android/wallpaper/ThemePickerTestModule.kt
index f4376ee..5ed8962 100644
--- a/tests/module/src/com/android/wallpaper/ThemePickerTestModule.kt
+++ b/tests/module/src/com/android/wallpaper/ThemePickerTestModule.kt
@@ -33,6 +33,8 @@
 import com.android.wallpaper.module.logging.UserEventLogger
 import com.android.wallpaper.modules.ThemePickerAppModule
 import com.android.wallpaper.network.Requester
+import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
+import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder
 import com.android.wallpaper.picker.di.modules.EffectsModule
 import com.android.wallpaper.picker.preview.data.util.FakeLiveWallpaperDownloader
 import com.android.wallpaper.picker.preview.data.util.LiveWallpaperDownloader
@@ -109,6 +111,12 @@
     @Singleton
     abstract fun bindEffectsController(impl: FakeEffectsController): EffectsController
 
+    @Binds
+    @Singleton
+    abstract fun bindCustomizationOptionsBinder(
+        impl: DefaultCustomizationOptionsBinder
+    ): CustomizationOptionsBinder
+
     companion object {
         @Provides
         @Singleton