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

Commit 77eca007 authored by George Lin's avatar George Lin
Browse files

Fix discard dialog showing when applying clock font

Test: Manually tested the issue is gone
Bug: 391856369
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I0368b54dfb3f8e8c01e26b1b33ee6765b88ef8ff
parent c4231f4b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ constructor(

    /** The currently-selected clock. This also emits the clock color information. */
    override val selectedClock: Flow<ClockMetadataModel> =
        callbackFlow {
        callbackFlow<ClockMetadataModel?> {
                fun send() {
                    val activeClockId = registry.activeClockId
                    val metadata = registry.settings?.metadata
@@ -146,6 +146,9 @@ constructor(
            }
            .flowOn(mainDispatcher)
            .mapNotNull { it }
            // Make this a shared flow to prevent ClockRegistry.registerClockChangeListener from
            // being called every time this flow is collected, since ClockRegistry is a singleton.
            .shareIn(mainScope, SharingStarted.WhileSubscribed(), 1)

    override suspend fun setSelectedClock(clockId: String) {
        registry.mutateSetting { oldSettings ->
+1 −1
Original line number Diff line number Diff line
@@ -401,7 +401,7 @@ object ClockFloatingSheetBinder {
        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    viewModel.selectedClockFontAxes.filterNotNull().collect { fontAxes ->
                    viewModel.previewingClockFontAxes.filterNotNull().collect { fontAxes ->
                        // This data flow updates only when a new clock style is selected. We
                        // initiate the clock font content with regard to that clock style.
                        sliderViewMap.clear()
+16 −13
Original line number Diff line number Diff line
@@ -187,14 +187,13 @@ constructor(

    // Clock font axis
    private val overrideClockFontAxisMap = MutableStateFlow<Map<String, Float>>(emptyMap())
    val selectedClockFontAxes =
    val previewingClockFontAxes =
        previewingClock
            .map { clock -> clock.fontAxes }
            .stateIn(viewModelScope, SharingStarted.Eagerly, null)
            .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1)
    private val selectedClockFontAxisMap =
        selectedClockFontAxes
            .filterNotNull()
            .map { fontAxes -> fontAxes.associate { it.key to it.currentValue } }
        selectedClock
            .map { clock -> clock.fontAxes.associate { it.key to it.currentValue } }
            .shareIn(viewModelScope, SharingStarted.WhileSubscribed(), 1)
    private val isFontAxisMapEdited =
        combine(overrideClockFontAxisMap, selectedClockFontAxisMap) {
@@ -432,9 +431,10 @@ constructor(
                isClockColorEdited ||
                isSliderProgressEdited
        }

    private val onApplyClicked: MutableStateFlow<Boolean> = MutableStateFlow(false)
    val onApply: Flow<(suspend () -> Unit)?> =
        combine(
            onApplyClicked,
            isEdited,
            previewingClock,
            previewingClockSize,
@@ -442,14 +442,16 @@ constructor(
            previewingSliderProgress,
            previewingClockFontAxisMap,
        ) { array ->
            val isEdited: Boolean = array[0] as Boolean
            val clock: ClockMetadataModel = array[1] as ClockMetadataModel
            val size: ClockSize = array[2] as ClockSize
            val previewingColorId: String = array[3] as String
            val previewProgress: Int = array[4] as Int
            val axisMap: Map<String, Float> = array[5] as Map<String, Float>
            if (isEdited) {
            val onApplyClicked: Boolean = array[0] as Boolean
            val isEdited: Boolean = array[1] as Boolean
            val clock: ClockMetadataModel = array[2] as ClockMetadataModel
            val size: ClockSize = array[3] as ClockSize
            val previewingColorId: String = array[4] as String
            val previewProgress: Int = array[5] as Int
            val axisMap: Map<String, Float> = array[6] as Map<String, Float>
            if (isEdited && !onApplyClicked) {
                {
                    this.onApplyClicked.value = true
                    clockPickerInteractor.applyClock(
                        clockId = clock.clockId,
                        size = size,
@@ -477,6 +479,7 @@ constructor(
        overridingSliderProgress.value = null
        overrideClockFontAxisMap.value = emptyMap()
        _selectedTab.value = Tab.STYLE
        onApplyClicked.value = false
    }

    companion object {