diff options
author | George Lin <giolin@google.com> | 2023-03-02 19:37:45 +0000 |
---|---|---|
committer | George Lin <giolin@google.com> | 2023-03-03 15:51:49 +0000 |
commit | 412c9bd722f5a0ebdb47892468f7f3646ef1dcfa (patch) | |
tree | d729968f5f897686a850a645b7420ca219f550cc /src/com/android/customization/picker/clock | |
parent | f486be7085d5d71365f150d04bfa16944589f1e3 (diff) | |
download | ThemePicker-412c9bd722f5a0ebdb47892468f7f3646ef1dcfa.tar.gz |
[TP] Smooth scroll to clock color option position
We should smooth scroll to clock color option position to make sure the
selected option is shown on the screen.
Test: manually tested that the selected color option shows on the screen
Bug: 270097085
Change-Id: Ie6cb75cac2c07f72d0ae1937a9bf932be1dd2de7
Diffstat (limited to 'src/com/android/customization/picker/clock')
-rw-r--r-- | src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt | 12 | ||||
-rw-r--r-- | src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModel.kt | 4 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt b/src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt index b63fd276..2ceb266e 100644 --- a/src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt +++ b/src/com/android/customization/picker/clock/ui/binder/ClockSettingsBinder.kt @@ -132,6 +132,18 @@ object ClockSettingsBinder { } launch { + viewModel.selectedColorOptionPosition.collect { selectedPosition -> + if (selectedPosition != -1) { + // We use "post" because we need to give the adapter item a pass to + // update the view. + colorOptionContainerView.post { + colorOptionContainerView.smoothScrollToPosition(selectedPosition) + } + } + } + } + + launch { viewModel.selectedClockSize.collect { size -> when (size) { ClockSize.DYNAMIC -> { diff --git a/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModel.kt b/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModel.kt index c9be43f2..23fbc7e4 100644 --- a/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModel.kt +++ b/src/com/android/customization/picker/clock/ui/viewmodel/ClockSettingsViewModel.kt @@ -181,6 +181,10 @@ private constructor( initialValue = emptyList(), ) + @OptIn(ExperimentalCoroutinesApi::class) + val selectedColorOptionPosition: Flow<Int> = + colorOptions.mapLatest { it.indexOfFirst { colorOption -> colorOption.isSelected } } + private fun ColorSeedOption.toColorOptionViewModel( context: Context, selectedColorId: String?, |