Merge "Use activityStarter of KeyguardQuickAffordancePickerViewModel to launch button intent" into udc-dev
diff --git a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
index 7bdd4fc..f455600 100644
--- a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
+++ b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
@@ -106,9 +106,7 @@
             LifecycleEventObserver { source, event ->
                 when (event) {
                     Lifecycle.Event.ON_RESUME -> {
-                        clockViewFactory.registerTimeTicker(source) {
-                            !carouselView.isCarouselInTransition
-                        }
+                        clockViewFactory.registerTimeTicker(source)
                     }
                     Lifecycle.Event.ON_PAUSE -> {
                         clockViewFactory.unregisterTimeTicker(source)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
index 059e498..3cf5471 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
@@ -36,8 +36,6 @@
         attrs,
     ) {
 
-    var isCarouselInTransition = false
-
     val carousel: Carousel
     private val motionLayout: MotionLayout
     private lateinit var adapter: ClockCarouselAdapter
@@ -72,7 +70,6 @@
                     startId: Int,
                     endId: Int
                 ) {
-                    isCarouselInTransition = true
                     val scalingDownClockId = adapter.clockIds[carousel.currentIndex]
                     val scalingUpIdx =
                         if (endId == R.id.next) (carousel.currentIndex + 1) % adapter.count()
@@ -125,7 +122,6 @@
                 }
 
                 override fun onTransitionCompleted(motionLayout: MotionLayout?, currentId: Int) {
-                    isCarouselInTransition = false
                     setCardAnimationState(currentId == R.id.start)
                 }
 
@@ -197,8 +193,6 @@
 
             clockHostView.removeAllViews()
             val clockView = onGetClockController(clockIds[index]).largeClock.view
-            // Making sure the large clock tick to the correct time
-            onGetClockController(clockIds[index]).largeClock.events.onTimeTick()
             // The clock view might still be attached to an existing parent. Detach before adding to
             // another parent.
             (clockView.parent as? ViewGroup)?.removeView(clockView)
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
index cf154d5..3c7bab1 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockViewFactory.kt
@@ -67,21 +67,13 @@
     }
 
     fun registerTimeTicker(owner: LifecycleOwner) {
-        registerTimeTicker(owner, null)
-    }
-
-    fun registerTimeTicker(owner: LifecycleOwner, shouldTimeTick: (() -> Boolean)?) {
         val hashCode = owner.hashCode()
         if (timeTickListeners.keys.contains(hashCode)) {
             return
         }
 
         timeTickListeners[hashCode] =
-            TimeTicker.registerNewReceiver(activity.applicationContext) {
-                if (shouldTimeTick == null || shouldTimeTick()) {
-                    onTimeTick()
-                }
-            }
+            TimeTicker.registerNewReceiver(activity.applicationContext) { onTimeTick() }
     }
 
     private fun onTimeTick() {
diff --git a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
index 3dba27e..3eadec5 100644
--- a/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
+++ b/src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt
@@ -92,6 +92,22 @@
                 launch {
                     viewModel.colorOptions.collect { colorOptions ->
                         colorOptionAdapter.setItems(colorOptions)
+                        // the same recycler view is used for different color types tabs
+                        // the scroll state of each tab should be independent of others
+                        var indexToFocus = 0
+                        colorOptions.forEachIndexed { index, colorOption ->
+                            if (colorOption.isSelected.value) {
+                                indexToFocus = index
+                            }
+                        }
+                        val linearLayoutManager =
+                            object : LinearLayoutManager(view.context, HORIZONTAL, false) {
+                                override fun onLayoutCompleted(state: RecyclerView.State?) {
+                                    super.onLayoutCompleted(state)
+                                    scrollToPosition(indexToFocus)
+                                }
+                            }
+                        colorOptionContainerView.layoutManager = linearLayoutManager
                     }
                 }
             }