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

Commit dc79f1f1 authored by George Lin's avatar George Lin
Browse files

Make clock picker view model aware of if edited

We check if the selected option is the same as the system one to see if
there are any changes. If yes, we will enable the on apply by emitting a
non null onApply function.

Test: Manually tested
Bug: 376092261
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I07ad844f96501bd67a6816c202eaacc199ea3e9f
parent 0ae53d6d
Loading
Loading
Loading
Loading
+52 −19
Original line number Diff line number Diff line
@@ -109,6 +109,12 @@ constructor(

    // Clock style
    private val overridingClock = MutableStateFlow<ClockMetadataModel?>(null)
    private val isClockEdited =
        combine(overridingClock, clockPickerInteractor.selectedClock) {
            overridingClock,
            selectedClock ->
            overridingClock != null && overridingClock.clockId != selectedClock.clockId
        }
    val previewingClock =
        combine(overridingClock, clockPickerInteractor.selectedClock) {
            overridingClock,
@@ -191,6 +197,12 @@ constructor(

    // Clock size
    private val overridingClockSize = MutableStateFlow<ClockSize?>(null)
    private val isClockSizeEdited =
        combine(overridingClockSize, clockPickerInteractor.selectedClockSize) {
            overridingClockSize,
            selectedClockSize ->
            overridingClockSize != null && overridingClockSize != selectedClockSize
        }
    val previewingClockSize =
        combine(overridingClockSize, clockPickerInteractor.selectedClockSize) {
            overridingClockSize,
@@ -210,6 +222,12 @@ constructor(
    // Clock color
    // 0 - 100
    private val overridingClockColorId = MutableStateFlow<String?>(null)
    private val isClockColorIdEdited =
        combine(overridingClockColorId, clockPickerInteractor.selectedColorId) {
            overridingClockColorId,
            selectedColorId ->
            overridingClockColorId != null && (overridingClockColorId != selectedColorId)
        }
    private val previewingClockColorId =
        combine(overridingClockColorId, clockPickerInteractor.selectedColorId) {
            overridingClockColorId,
@@ -218,6 +236,12 @@ constructor(
        }

    private val overridingSliderProgress = MutableStateFlow<Int?>(null)
    private val isSliderProgressEdited =
        combine(overridingSliderProgress, clockPickerInteractor.colorToneProgress) {
            overridingSliderProgress,
            colorToneProgress ->
            overridingSliderProgress != null && (overridingSliderProgress != colorToneProgress)
        }
    val previewingSliderProgress: Flow<Int> =
        combine(overridingSliderProgress, clockPickerInteractor.colorToneProgress) {
            overridingSliderProgress,
@@ -357,32 +381,41 @@ constructor(
        )
    }

    private val isEdited =
        combine(isClockEdited, isClockSizeEdited, isClockColorIdEdited, isSliderProgressEdited) {
            isClockEdited,
            isClockSizeEdited,
            isClockColorEdited,
            isSliderProgressEdited ->
            isClockEdited || isClockSizeEdited || isClockColorEdited || isSliderProgressEdited
        }
    val onApply: Flow<(suspend () -> Unit)?> =
        combine(
            isEdited,
            previewingClock,
            previewingClockSize,
            previewingClockColorId,
            previewingSliderProgress,
        ) { clock, size, colorId, progress ->
        ) { isEdited, clock, size, previewingColorId, previewProgress ->
            if (isEdited) {
                {
                val clockColorViewModel = colorMap[colorId]
                val seedColor =
                    if (clockColorViewModel != null) {
                        blendColorWithTone(
                            color = clockColorViewModel.color,
                            colorTone = clockColorViewModel.getColorTone(progress),
                        )
                    } else {
                        null
                    }
                    clockPickerInteractor.applyClock(
                        clockId = clock.clockId,
                        size = size,
                    selectedColorId = if (colorId == DEFAULT_CLOCK_COLOR_ID) null else colorId,
                    colorToneProgress = progress,
                    seedColor = seedColor,
                        selectedColorId = previewingColorId,
                        colorToneProgress = previewProgress,
                        seedColor =
                            colorMap[previewingColorId]?.let {
                                blendColorWithTone(
                                    color = it.color,
                                    colorTone = it.getColorTone(previewProgress),
                                )
                            },
                    )
                }
            } else {
                null
            }
        }

    fun resetPreview() {