Color Picker Fragment Preview (1/2)

Added home & lock preview within the new color fragment

Bug: 262924623
Test: Manual Verified, screen recording - https://drive.google.com/file/d/1TNI5vRGmrA3M1V6P--nBWtcLJGlryTD6/view?usp=sharing&resourcekey=0-ly9J8yG0Y6hzJ2XWaj3pPw
Change-Id: Id5c12034bba741fec4c9854ee4aa61d6dcc66286
diff --git a/res/layout/fragment_color_picker.xml b/res/layout/fragment_color_picker.xml
index bf0c414..1e8fc15 100644
--- a/res/layout/fragment_color_picker.xml
+++ b/res/layout/fragment_color_picker.xml
@@ -30,21 +30,28 @@
 
     </FrameLayout>
 
-    <com.android.wallpaper.picker.DisplayAspectRatioFrameLayout
+    <com.android.wallpaper.picker.DisplayAspectRatioLinearLayout
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
+        android:layout_marginHorizontal="24dp"
         android:paddingTop="36dp"
-        android:paddingBottom="40dp">
+        android:paddingBottom="40dp"
+        android:orientation="horizontal"
+        android:gravity="center_vertical">
 
         <include
-            android:id="@+id/preview"
+            android:id="@+id/lock_preview"
             layout="@layout/wallpaper_preview_card"
-            android:layout_width="0dp"
-            android:layout_height="match_parent"
-            android:layout_gravity="center"/>
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
 
-    </com.android.wallpaper.picker.DisplayAspectRatioFrameLayout>
+        <include
+            android:id="@+id/home_preview"
+            layout="@layout/wallpaper_preview_card"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+    </com.android.wallpaper.picker.DisplayAspectRatioLinearLayout>
 
     <LinearLayout
         android:layout_width="match_parent"
diff --git a/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt b/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
index 9b707a3..fad7def 100644
--- a/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
+++ b/src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt
@@ -19,6 +19,7 @@
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
+import androidx.cardview.widget.CardView
 import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.get
 import com.android.customization.module.ThemePickerInjector
@@ -27,8 +28,16 @@
 import com.android.wallpaper.model.WallpaperColorsViewModel
 import com.android.wallpaper.module.InjectorProvider
 import com.android.wallpaper.picker.AppbarFragment
+import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder
+import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel
+import com.android.wallpaper.util.DisplayUtils
+import com.android.wallpaper.util.PreviewUtils
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.suspendCancellableCoroutine
 
+@OptIn(ExperimentalCoroutinesApi::class)
 class ColorPickerFragment : AppbarFragment() {
+
     override fun onCreateView(
         inflater: LayoutInflater,
         container: ViewGroup?,
@@ -42,6 +51,10 @@
             )
         setUpToolbar(view)
         val injector = InjectorProvider.getInjector() as ThemePickerInjector
+        val lockScreenView: CardView = view.requireViewById(R.id.lock_preview)
+        val homeScreenView: CardView = view.requireViewById(R.id.home_preview)
+        val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext())
+        val displayUtils: DisplayUtils = injector.getDisplayUtils(requireContext())
         val wcViewModel = ViewModelProvider(requireActivity())[WallpaperColorsViewModel::class.java]
         ColorPickerBinder.bind(
             view = view,
@@ -56,6 +69,68 @@
                     .get(),
             lifecycleOwner = this,
         )
+        ScreenPreviewBinder.bind(
+            activity = requireActivity(),
+            previewView = lockScreenView,
+            viewModel =
+                ScreenPreviewViewModel(
+                    previewUtils =
+                        PreviewUtils(
+                            context = requireContext(),
+                            authority =
+                                requireContext()
+                                    .getString(
+                                        R.string.lock_screen_preview_provider_authority,
+                                    ),
+                        ),
+                    wallpaperInfoProvider = {
+                        suspendCancellableCoroutine { continuation ->
+                            wallpaperInfoFactory.createCurrentWallpaperInfos(
+                                { homeWallpaper, lockWallpaper, _ ->
+                                    continuation.resume(lockWallpaper ?: homeWallpaper, null)
+                                },
+                                /* forceRefresh= */ true,
+                            )
+                        }
+                    },
+                    onWallpaperColorChanged = { colors ->
+                        wcViewModel.setLockWallpaperColors(colors)
+                    },
+                ),
+            lifecycleOwner = this,
+            offsetToStart = displayUtils.isOnWallpaperDisplay(requireActivity()),
+        )
+        ScreenPreviewBinder.bind(
+            activity = requireActivity(),
+            previewView = homeScreenView,
+            viewModel =
+                ScreenPreviewViewModel(
+                    previewUtils =
+                        PreviewUtils(
+                            context = requireContext(),
+                            authorityMetadataKey =
+                                requireContext()
+                                    .getString(
+                                        R.string.grid_control_metadata_name,
+                                    ),
+                        ),
+                    wallpaperInfoProvider = {
+                        suspendCancellableCoroutine { continuation ->
+                            wallpaperInfoFactory.createCurrentWallpaperInfos(
+                                { homeWallpaper, lockWallpaper, _ ->
+                                    continuation.resume(homeWallpaper ?: lockWallpaper, null)
+                                },
+                                /* forceRefresh= */ true,
+                            )
+                        }
+                    },
+                    onWallpaperColorChanged = { colors ->
+                        wcViewModel.setLockWallpaperColors(colors)
+                    },
+                ),
+            lifecycleOwner = this,
+            offsetToStart = displayUtils.isOnWallpaperDisplay(requireActivity()),
+        )
         return view
     }