Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 646783d5 authored by abdullahirum's avatar abdullahirum
Browse files

Update List positions for shortcuts and grid layout

This CL adjusts the lists for shortcuts and grid layouts to enable single pointer navigation

Fix: 386020114
Flag: com.android.systemui.shared.new_customization_picker_ui
Test: manual
Change-Id: If5f058d846932d2eb5ab28e956bc035961c1d6da
parent 43e84aee
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -423,8 +423,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)
                            }
                        }
                    }
                }

+11 −8
Original line number Diff line number Diff line
@@ -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
@@ -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)
                    }
                }

+18 −0
Original line number Diff line number Diff line
@@ -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
@@ -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)
                            }
                        }
                    }
                }
            }
        }
    }
+20 −0
Original line number Diff line number Diff line
@@ -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
@@ -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 ->
+19 −3
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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)?> =
@@ -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)
@@ -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