Merge "Auto-scroll to the selected quick affordance." into tm-qpr-dev am: 3de761e8eb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ThemePicker/+/21063807

Change-Id: I40feb10bb3453972dc90ea0e16166722c1e11634
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
index 74d38b1..30372fe 100644
--- a/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
+++ b/src/com/android/customization/picker/quickaffordance/ui/binder/KeyguardQuickAffordancePickerBinder.kt
@@ -74,6 +74,16 @@
                 launch {
                     viewModel.quickAffordances.collect { affordances ->
                         affordancesAdapter.setItems(affordances)
+
+                        // Scroll the view to show the first selected affordance.
+                        val selectedPosition = affordances.indexOfFirst { it.isSelected }
+                        if (selectedPosition != -1) {
+                            // We use "post" because we need to give the adapter item a pass to
+                            // update the view.
+                            affordancesView.post {
+                                affordancesView.smoothScrollToPosition(selectedPosition)
+                            }
+                        }
                     }
                 }