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

Commit 2fb3500d authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Update keyguard preview when clock size setting changes

Bug: 375207082
Flag: NONE Bugfix
Test: Manually checked button function
Change-Id: I4f63a72681a05907cee9b6e411e0cd90e51500fa
parent c26379f2
Loading
Loading
Loading
Loading
+35 −34
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockPreviewConfig
import com.android.systemui.shared.clocks.ClockRegistry
import kotlinx.coroutines.flow.combine

/** Binder for the small clock view, large clock view. */
object KeyguardPreviewClockViewBinder {
@@ -76,7 +77,8 @@ object KeyguardPreviewClockViewBinder {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                var lastClock: ClockController? = null
                launch("$TAG#viewModel.previewClock") {
                        viewModel.previewClock.collect { currentClock ->
                        combine(viewModel.previewClock, viewModel.selectedClockSize, ::Pair)
                            .collect { (currentClock, clockSize) ->
                                lastClock?.let { clock ->
                                    (clock.largeClock.layout.views + clock.smallClock.layout.views)
                                        .forEach { rootView.removeView(it) }
@@ -105,7 +107,7 @@ object KeyguardPreviewClockViewBinder {
                                    clockPreviewConfig,
                                    rootView,
                                    currentClock,
                                viewModel,
                                    clockSize,
                                )
                            }
                    }
@@ -133,7 +135,7 @@ object KeyguardPreviewClockViewBinder {
        clockPreviewConfig: ClockPreviewConfig,
        rootView: ConstraintLayout,
        previewClock: ClockController,
        viewModel: KeyguardPreviewClockViewModel,
        clockSize: ClockSizeSetting?,
    ) {
        val cs = ConstraintSet().apply { clone(rootView) }

@@ -147,16 +149,15 @@ object KeyguardPreviewClockViewBinder {
        previewClock.largeClock.layout.applyPreviewConstraints(configWithUpdatedLockId, cs)
        previewClock.smallClock.layout.applyPreviewConstraints(configWithUpdatedLockId, cs)

        // When selectedClockSize is the initial value, make both clocks invisible to avoid
        // flickering
        // When selectedClockSize is the initial value, make both clocks invisible to avoid flicker
        val largeClockVisibility =
            when (viewModel.selectedClockSize.value) {
            when (clockSize) {
                ClockSizeSetting.DYNAMIC -> VISIBLE
                ClockSizeSetting.SMALL -> INVISIBLE
                null -> INVISIBLE
            }
        val smallClockVisibility =
            when (viewModel.selectedClockSize.value) {
            when (clockSize) {
                ClockSizeSetting.DYNAMIC -> INVISIBLE
                ClockSizeSetting.SMALL -> VISIBLE
                null -> INVISIBLE