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

Commit 0f3b6622 authored by Catherine Liang's avatar Catherine Liang
Browse files

Fix inability to select default clock color option

Default clock color option could not be selected due to the fact that
the default clock color id was null. Therefore, when it is selected, the
overriding clock color id is set to null. This is confounding because
the overriding value being null could signal either that the default
clock color was selected, or no overriding clock color was selected, and
in the current logic, we assume the latter, and therefore provide the
system selected color id instead. Give default clock color option an id
to fix the problem.

Flag: com.android.systemui.shared.new_customization_picker_ui
Test: Manually verified
Test: ClockPickerViewModelTest passes
Bug: 369114305

Change-Id: I425da6159b338f80e6ded7fdb7a9240b062dd456
parent f5eda4ab
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ constructor(
        combine(overridingClockColorId, clockPickerInteractor.selectedColorId) {
            overridingClockColorId,
            selectedColorId ->
            overridingClockColorId ?: selectedColorId
            overridingClockColorId ?: selectedColorId ?: DEFAULT_CLOCK_COLOR_ID
        }

    private val overridingSliderProgress = MutableStateFlow<Int?>(null)
@@ -224,8 +224,7 @@ constructor(
        }
    val isSliderEnabled: Flow<Boolean> =
        combine(previewingClock, previewingClockColorId) { clock, clockColorId ->
                // clockColorId null means clock color is the system theme color, thus no slider
                clock.isReactiveToTone && clockColorId != null
                clock.isReactiveToTone && clockColorId != DEFAULT_CLOCK_COLOR_ID
            }
            .distinctUntilChanged()

@@ -235,7 +234,8 @@ constructor(

    val previewingSeedColor: Flow<Int?> =
        combine(previewingClockColorId, previewingSliderProgress) { clockColorId, sliderProgress ->
            val clockColorViewModel = if (clockColorId == null) null else colorMap[clockColorId]
            val clockColorViewModel =
                if (clockColorId == DEFAULT_CLOCK_COLOR_ID) null else colorMap[clockColorId]
            if (clockColorViewModel == null) {
                null
            } else {
@@ -322,7 +322,8 @@ constructor(
                /** darkTheme= */
                true
            )
        val isSelectedFlow = previewingClockColorId.map { it == null }.stateIn(viewModelScope)
        val isSelectedFlow =
            previewingClockColorId.map { it == DEFAULT_CLOCK_COLOR_ID }.stateIn(viewModelScope)
        return OptionItemViewModel<ColorOptionIconViewModel>(
            key = MutableStateFlow(key) as StateFlow<String>,
            payload =
@@ -345,7 +346,7 @@ constructor(
                        null
                    } else {
                        {
                            overridingClockColorId.value = null
                            overridingClockColorId.value = DEFAULT_CLOCK_COLOR_ID
                            overridingSliderProgress.value =
                                ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS
                        }
@@ -375,7 +376,7 @@ constructor(
                clockPickerInteractor.applyClock(
                    clockId = clock.clockId,
                    size = size,
                    selectedColorId = colorId,
                    selectedColorId = if (colorId == DEFAULT_CLOCK_COLOR_ID) null else colorId,
                    colorToneProgress = progress,
                    seedColor = seedColor,
                )
@@ -391,6 +392,7 @@ constructor(
    }

    companion object {
        private const val DEFAULT_CLOCK_COLOR_ID = "DEFAULT"
        private val helperColorLab: DoubleArray by lazy { DoubleArray(3) }

        fun blendColorWithTone(color: Int, colorTone: Double): Int {