Loading src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt +2 −4 Original line number Diff line number Diff line Loading @@ -51,11 +51,9 @@ class ColorPickerRepositoryImpl( private val _isApplyingSystemColor = MutableStateFlow(false) override val isApplyingSystemColor = _isApplyingSystemColor.asStateFlow() // TODO (b/299510645): update color options on selected option change after restart is disabled override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> = combine(homeWallpaperColors, lockWallpaperColors, selectedColorOption) { homeColors, lockColors, _ -> combine(homeWallpaperColors, lockWallpaperColors) { homeColors, lockColors -> homeColors to lockColors } .map { (homeColors, lockColors) -> Loading src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt +16 −20 Original line number Diff line number Diff line Loading @@ -93,29 +93,21 @@ object ColorPickerBinder { launch { viewModel.colorOptions.collect { colorOptions -> colorOptionAdapter.setItems(colorOptions) // only set or restore instance state on a recycler view once data binding // is complete to ensure scroll position is reflected correctly 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 if (layoutManagerSavedState != null) { colorOptionContainerView.post { (colorOptionContainerView.layoutManager as LinearLayoutManager) .onRestoreInstanceState(layoutManagerSavedState) layoutManagerSavedState = null } } else { var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value } indexToFocus = if (indexToFocus < 0) 0 else indexToFocus val linearLayoutManager = object : LinearLayoutManager(view.context, HORIZONTAL, false) { override fun onLayoutCompleted(state: RecyclerView.State?) { super.onLayoutCompleted(state) // scrollToPosition seems to be inconsistently moving // selected // color to different positions scrollToPositionWithOffset(indexToFocus, 0) } (colorOptionContainerView.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, 0) } colorOptionContainerView.layoutManager = linearLayoutManager } } } Loading @@ -123,9 +115,13 @@ object ColorPickerBinder { } return object : Binding { override fun saveInstanceState(savedState: Bundle) { // as a workaround for the picker restarting twice after a config change, if the // picker restarts before the saved state was applied and set to null, // re-use the same saved state savedState.putParcelable( LAYOUT_MANAGER_SAVED_STATE, colorOptionContainerView.layoutManager?.onSaveInstanceState() layoutManagerSavedState ?: colorOptionContainerView.layoutManager?.onSaveInstanceState() ) } Loading Loading
src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt +2 −4 Original line number Diff line number Diff line Loading @@ -51,11 +51,9 @@ class ColorPickerRepositoryImpl( private val _isApplyingSystemColor = MutableStateFlow(false) override val isApplyingSystemColor = _isApplyingSystemColor.asStateFlow() // TODO (b/299510645): update color options on selected option change after restart is disabled override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> = combine(homeWallpaperColors, lockWallpaperColors, selectedColorOption) { homeColors, lockColors, _ -> combine(homeWallpaperColors, lockWallpaperColors) { homeColors, lockColors -> homeColors to lockColors } .map { (homeColors, lockColors) -> Loading
src/com/android/customization/picker/color/ui/binder/ColorPickerBinder.kt +16 −20 Original line number Diff line number Diff line Loading @@ -93,29 +93,21 @@ object ColorPickerBinder { launch { viewModel.colorOptions.collect { colorOptions -> colorOptionAdapter.setItems(colorOptions) // only set or restore instance state on a recycler view once data binding // is complete to ensure scroll position is reflected correctly 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 if (layoutManagerSavedState != null) { colorOptionContainerView.post { (colorOptionContainerView.layoutManager as LinearLayoutManager) .onRestoreInstanceState(layoutManagerSavedState) layoutManagerSavedState = null } } else { var indexToFocus = colorOptions.indexOfFirst { it.isSelected.value } indexToFocus = if (indexToFocus < 0) 0 else indexToFocus val linearLayoutManager = object : LinearLayoutManager(view.context, HORIZONTAL, false) { override fun onLayoutCompleted(state: RecyclerView.State?) { super.onLayoutCompleted(state) // scrollToPosition seems to be inconsistently moving // selected // color to different positions scrollToPositionWithOffset(indexToFocus, 0) } (colorOptionContainerView.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, 0) } colorOptionContainerView.layoutManager = linearLayoutManager } } } Loading @@ -123,9 +115,13 @@ object ColorPickerBinder { } return object : Binding { override fun saveInstanceState(savedState: Bundle) { // as a workaround for the picker restarting twice after a config change, if the // picker restarts before the saved state was applied and set to null, // re-use the same saved state savedState.putParcelable( LAYOUT_MANAGER_SAVED_STATE, colorOptionContainerView.layoutManager?.onSaveInstanceState() layoutManagerSavedState ?: colorOptionContainerView.layoutManager?.onSaveInstanceState() ) } Loading