Loading src/com/android/wallpaper/customization/ui/binder/ClockFloatingSheetBinder.kt +12 −2 Original line number Diff line number Diff line Loading @@ -436,8 +436,18 @@ object ClockFloatingSheetBinder { launch { viewModel.previewingClockColorOptionIndex.collect { indexToFocus -> (clockColorList.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, 0) clockColorList.post { val layoutManager = clockColorList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(indexToFocus) if (itemView != null) { val parentCenter = clockColorList.width / 2 val itemCenter = itemView.left + itemView.width / 2 + itemView.width val scrollBy = itemCenter - parentCenter clockColorList.smoothScrollBy(scrollBy, 0) } } } } Loading src/com/android/wallpaper/customization/ui/binder/ColorsFloatingSheetBinder.kt +11 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.view.ViewGroup import android.widget.TextView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.core.view.isEmpty import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope Loading Loading @@ -145,14 +144,18 @@ object ColorsFloatingSheetBinder { launch { colorsViewModel.previewingColorOptionIndex.collect { indexToFocus -> val offset = if (colorsList != null && !colorsList.isEmpty()) { colorsList.get(0).width } else { 0 colorsList.post { val layoutManager = colorsList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(indexToFocus) if (itemView != null) { val parentCenter = colorsList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter colorsList.smoothScrollBy(scrollBy, 0) } } (colorsList.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, offset) } } Loading src/com/android/wallpaper/customization/ui/binder/GridFloatingSheetBinder.kt +18 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope Loading Loading @@ -90,6 +91,23 @@ object GridFloatingSheetBinder { } } } launch { viewModel.selectedGridOptionIndex.collect { index -> gridOptionList.post { val layoutManager = gridOptionList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(index) if (itemView != null) { val parentCenter = gridOptionList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter gridOptionList.smoothScrollBy(scrollBy, 0) } } } } } } } Loading src/com/android/wallpaper/customization/ui/binder/ShortcutFloatingSheetBinder.kt +20 −0 Original line number Diff line number Diff line Loading @@ -22,11 +22,13 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.android.customization.picker.common.ui.view.DoubleRowListItemSpacing import com.android.themepicker.R Loading Loading @@ -116,6 +118,24 @@ object ShortcutFloatingSheetBinder { } } launch { viewModel.selectedQuickAffordanceIndex.collect { index -> quickAffordanceList.post { val layoutManager = quickAffordanceList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(index) if (itemView != null) { val parentCenter = quickAffordanceList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter quickAffordanceList.smoothScrollBy(scrollBy, 0) } } } } launch { viewModel.quickAffordances .flatMapLatest { affordances -> Loading src/com/android/wallpaper/customization/ui/viewmodel/GridPickerViewModel.kt +19 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map Loading @@ -51,6 +52,9 @@ constructor( ) { val isGridCustomizationAvailable = interactor.isGridCustomizationAvailable val _selectedGridOptionIndex = MutableStateFlow<Int>(0) val selectedGridOptionIndex = _selectedGridOptionIndex.asStateFlow() // The currently-set system grid option val selectedGridOption = interactor.selectedGridOption Loading @@ -71,7 +75,11 @@ constructor( .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1) val gridOptionListItems: Flow<List<OptionItemViewModel2<Drawable>>> = gridOptions .map { gridOptions -> gridOptions.map { toGridOptionItemViewModel(it) } } .map { gridOptions -> gridOptions.mapIndexed { index, gridOption -> toGridOptionItemViewModel(gridOption, index) } } .shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1) val onApply: Flow<(suspend () -> Unit)?> = Loading @@ -95,7 +103,10 @@ constructor( overridingGridKey.value = null } private fun toGridOptionItemViewModel(option: GridOptionModel): OptionItemViewModel2<Drawable> { private fun toGridOptionItemViewModel( option: GridOptionModel, index: Int = -1, ): OptionItemViewModel2<Drawable> { // Fallback to use GridTileDrawable when no resource found for the icon ID val drawable = interactor.getGridOptionDrawable(option.iconId) Loading Loading @@ -127,7 +138,12 @@ constructor( onClicked = isSelected.map { if (!it) { { overridingGridKey.value = option.key } { if (index > -1) { _selectedGridOptionIndex.value = index } overridingGridKey.value = option.key } } else { null } Loading Loading
src/com/android/wallpaper/customization/ui/binder/ClockFloatingSheetBinder.kt +12 −2 Original line number Diff line number Diff line Loading @@ -436,8 +436,18 @@ object ClockFloatingSheetBinder { launch { viewModel.previewingClockColorOptionIndex.collect { indexToFocus -> (clockColorList.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, 0) clockColorList.post { val layoutManager = clockColorList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(indexToFocus) if (itemView != null) { val parentCenter = clockColorList.width / 2 val itemCenter = itemView.left + itemView.width / 2 + itemView.width val scrollBy = itemCenter - parentCenter clockColorList.smoothScrollBy(scrollBy, 0) } } } } Loading
src/com/android/wallpaper/customization/ui/binder/ColorsFloatingSheetBinder.kt +11 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.view.ViewGroup import android.widget.TextView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.core.view.isEmpty import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope Loading Loading @@ -145,14 +144,18 @@ object ColorsFloatingSheetBinder { launch { colorsViewModel.previewingColorOptionIndex.collect { indexToFocus -> val offset = if (colorsList != null && !colorsList.isEmpty()) { colorsList.get(0).width } else { 0 colorsList.post { val layoutManager = colorsList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(indexToFocus) if (itemView != null) { val parentCenter = colorsList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter colorsList.smoothScrollBy(scrollBy, 0) } } (colorsList.layoutManager as LinearLayoutManager) .scrollToPositionWithOffset(indexToFocus, offset) } } Loading
src/com/android/wallpaper/customization/ui/binder/GridFloatingSheetBinder.kt +18 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope Loading Loading @@ -90,6 +91,23 @@ object GridFloatingSheetBinder { } } } launch { viewModel.selectedGridOptionIndex.collect { index -> gridOptionList.post { val layoutManager = gridOptionList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(index) if (itemView != null) { val parentCenter = gridOptionList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter gridOptionList.smoothScrollBy(scrollBy, 0) } } } } } } } Loading
src/com/android/wallpaper/customization/ui/binder/ShortcutFloatingSheetBinder.kt +20 −0 Original line number Diff line number Diff line Loading @@ -22,11 +22,13 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.get import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.android.customization.picker.common.ui.view.DoubleRowListItemSpacing import com.android.themepicker.R Loading Loading @@ -116,6 +118,24 @@ object ShortcutFloatingSheetBinder { } } launch { viewModel.selectedQuickAffordanceIndex.collect { index -> quickAffordanceList.post { val layoutManager = quickAffordanceList.layoutManager as? LinearLayoutManager ?: return@post val itemView = layoutManager.findViewByPosition(index) if (itemView != null) { val parentCenter = quickAffordanceList.width / 2 val itemCenter = itemView.left + itemView.width / 2 val scrollBy = itemCenter - parentCenter quickAffordanceList.smoothScrollBy(scrollBy, 0) } } } } launch { viewModel.quickAffordances .flatMapLatest { affordances -> Loading
src/com/android/wallpaper/customization/ui/viewmodel/GridPickerViewModel.kt +19 −3 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map Loading @@ -51,6 +52,9 @@ constructor( ) { val isGridCustomizationAvailable = interactor.isGridCustomizationAvailable val _selectedGridOptionIndex = MutableStateFlow<Int>(0) val selectedGridOptionIndex = _selectedGridOptionIndex.asStateFlow() // The currently-set system grid option val selectedGridOption = interactor.selectedGridOption Loading @@ -71,7 +75,11 @@ constructor( .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1) val gridOptionListItems: Flow<List<OptionItemViewModel2<Drawable>>> = gridOptions .map { gridOptions -> gridOptions.map { toGridOptionItemViewModel(it) } } .map { gridOptions -> gridOptions.mapIndexed { index, gridOption -> toGridOptionItemViewModel(gridOption, index) } } .shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1) val onApply: Flow<(suspend () -> Unit)?> = Loading @@ -95,7 +103,10 @@ constructor( overridingGridKey.value = null } private fun toGridOptionItemViewModel(option: GridOptionModel): OptionItemViewModel2<Drawable> { private fun toGridOptionItemViewModel( option: GridOptionModel, index: Int = -1, ): OptionItemViewModel2<Drawable> { // Fallback to use GridTileDrawable when no resource found for the icon ID val drawable = interactor.getGridOptionDrawable(option.iconId) Loading Loading @@ -127,7 +138,12 @@ constructor( onClicked = isSelected.map { if (!it) { { overridingGridKey.value = option.key } { if (index > -1) { _selectedGridOptionIndex.value = index } overridingGridKey.value = option.key } } else { null } Loading