Auto-scroll to the selected quick affordance.

Fix: 266006047
Test: manually verified switching tabs or making selections correctly
and beautifully scrolls such that the selected affordance is visible.

Change-Id: I244c711eef4307528a361944b0dc03bab03aced4
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 57e9401..e412020 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)
+                            }
+                        }
                     }
                 }