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

Commit c6c581e7 authored by Hawkwood's avatar Hawkwood
Browse files

Dedupe unessecary theme updates

Bug: 401288687
Test: Manually checked color function
Flag: NONE Color api usage change
Change-Id: Ib4bfaf0fbef40256dbb35e032a2b30f3428e3aa2
parent afeda299
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ interface ClockFaceController {

    @get:SimpleProperty
    /** Current theme information the clock is using */
    val theme: ThemeConfig
    var theme: ThemeConfig

    @get:SimpleProperty
    /** Events specific to this clock face */
@@ -44,4 +44,13 @@ interface ClockFaceController {
    @get:SimpleProperty
    /** Triggers for various animations */
    val animations: ClockAnimations

    companion object {
        fun ClockFaceController.updateTheme(mutateTheme: (ThemeConfig) -> ThemeConfig) {
            val theme = mutateTheme(this.theme)
            if (this.theme == theme) return
            events.onThemeChanged(theme)
            this.theme = theme
        }
    }
}
+5 −4
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import com.android.systemui.plugins.clocks.AlarmData
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockEventListener
import com.android.systemui.plugins.clocks.ClockFaceController
import com.android.systemui.plugins.clocks.ClockFaceController.Companion.updateTheme
import com.android.systemui.plugins.clocks.ClockMessageBuffers
import com.android.systemui.plugins.clocks.ClockTickRate
import com.android.systemui.plugins.clocks.VRectF
@@ -263,19 +264,19 @@ constructor(
        if (regionSamplingEnabled) {
            clock?.smallClock?.run {
                val isDark = smallRegionSampler?.currentRegionDarkness()?.isDark ?: isDarkTheme
                events.onThemeChanged(theme.copy(isDarkTheme = isDark))
                updateTheme { it.copy(isDarkTheme = isDark) }
            }
            clock?.largeClock?.run {
                val isDark = largeRegionSampler?.currentRegionDarkness()?.isDark ?: isDarkTheme
                events.onThemeChanged(theme.copy(isDarkTheme = isDark))
                updateTheme { it.copy(isDarkTheme = isDark) }
            }
            return
        }

        clock?.run {
            Log.i(TAG, "isThemeDark: $isDarkTheme")
            smallClock.events.onThemeChanged(smallClock.theme.copy(isDarkTheme = isDarkTheme))
            largeClock.events.onThemeChanged(largeClock.theme.copy(isDarkTheme = isDarkTheme))
            smallClock.updateTheme { it.copy(isDarkTheme = isDarkTheme) }
            largeClock.updateTheme { it.copy(isDarkTheme = isDarkTheme) }
        }
    }

+21 −20
Original line number Diff line number Diff line
@@ -163,6 +163,7 @@ object KeyguardClockViewBinder {
                repeatOnLifecycle(Lifecycle.State.STARTED) {
                    viewModel.currentClock.collect { currentClock ->
                        currentClock?.apply {
                            // Reapply existing theme
                            smallClock.run { events.onThemeChanged(theme) }
                            largeClock.run { events.onThemeChanged(theme) }
                        }
+3 −10
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.ui.view.layout.sections.setVisibility
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockFaceController.Companion.updateTheme
import com.android.systemui.plugins.clocks.ClockPreviewConfig
import com.android.systemui.shared.clocks.ClockRegistry
import kotlinx.coroutines.flow.combine
@@ -114,16 +115,8 @@ object KeyguardPreviewClockViewBinder {
                    .invokeOnCompletion {
                        // recover seed color especially for Transit clock
                        lastClock?.apply {
                            smallClock.run {
                                events.onThemeChanged(
                                    theme.copy(seedColor = clockRegistry.seedColor)
                                )
                            }
                            largeClock.run {
                                events.onThemeChanged(
                                    theme.copy(seedColor = clockRegistry.seedColor)
                                )
                            }
                            smallClock.updateTheme { it.copy(seedColor = clockRegistry.seedColor) }
                            largeClock.updateTheme { it.copy(seedColor = clockRegistry.seedColor) }
                        }
                        lastClock = null
                    }
+2 −2
Original line number Diff line number Diff line
@@ -153,8 +153,8 @@ class ClockEventControllerTest : SysuiTestCase() {
            .thenReturn(ClockFaceConfig(tickRate = ClockTickRate.PER_MINUTE))
        whenever(largeClockController.config)
            .thenReturn(ClockFaceConfig(tickRate = ClockTickRate.PER_MINUTE))
        whenever(smallClockController.theme).thenReturn(ThemeConfig(true, null))
        whenever(largeClockController.theme).thenReturn(ThemeConfig(true, null))
        whenever(smallClockController.theme).thenReturn(ThemeConfig(false, null))
        whenever(largeClockController.theme).thenReturn(ThemeConfig(false, null))
        whenever(userTracker.userId).thenReturn(1)

        repository = kosmos.fakeKeyguardRepository