diff options
author | 2025-02-15 17:33:54 +0000 | |
---|---|---|
committer | 2025-02-15 17:54:08 +0000 | |
commit | 2fb3500da9e618979e7b46dfed791ba962f691cd (patch) | |
tree | 66a41bb39843b04491d30093edf4059b022112fa | |
parent | c26379f212e327cbf9ee93b3f72fb08be07a1b82 (diff) |
Update keyguard preview when clock size setting changes
Bug: 375207082
Flag: NONE Bugfix
Test: Manually checked button function
Change-Id: I4f63a72681a05907cee9b6e411e0cd90e51500fa
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt index d3b76a576a0f..a42682b6f537 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt @@ -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,38 +77,39 @@ object KeyguardPreviewClockViewBinder { repeatOnLifecycle(Lifecycle.State.STARTED) { var lastClock: ClockController? = null launch("$TAG#viewModel.previewClock") { - viewModel.previewClock.collect { currentClock -> - lastClock?.let { clock -> - (clock.largeClock.layout.views + clock.smallClock.layout.views) - .forEach { rootView.removeView(it) } - } - lastClock = currentClock - updateClockAppearance( - currentClock, - clockPreviewConfig.context.resources, - ) + combine(viewModel.previewClock, viewModel.selectedClockSize, ::Pair) + .collect { (currentClock, clockSize) -> + lastClock?.let { clock -> + (clock.largeClock.layout.views + clock.smallClock.layout.views) + .forEach { rootView.removeView(it) } + } + lastClock = currentClock + updateClockAppearance( + currentClock, + clockPreviewConfig.context.resources, + ) - if (viewModel.shouldHighlightSelectedAffordance) { - (currentClock.largeClock.layout.views + - currentClock.smallClock.layout.views) - .forEach { it.alpha = KeyguardPreviewRenderer.DIM_ALPHA } - } - currentClock.largeClock.layout.views.forEach { - (it.parent as? ViewGroup)?.removeView(it) - rootView.addView(it) - } + if (viewModel.shouldHighlightSelectedAffordance) { + (currentClock.largeClock.layout.views + + currentClock.smallClock.layout.views) + .forEach { it.alpha = KeyguardPreviewRenderer.DIM_ALPHA } + } + currentClock.largeClock.layout.views.forEach { + (it.parent as? ViewGroup)?.removeView(it) + rootView.addView(it) + } - currentClock.smallClock.layout.views.forEach { - (it.parent as? ViewGroup)?.removeView(it) - rootView.addView(it) + currentClock.smallClock.layout.views.forEach { + (it.parent as? ViewGroup)?.removeView(it) + rootView.addView(it) + } + applyPreviewConstraints( + clockPreviewConfig, + rootView, + currentClock, + clockSize, + ) } - applyPreviewConstraints( - clockPreviewConfig, - rootView, - currentClock, - viewModel, - ) - } } .invokeOnCompletion { // recover seed color especially for Transit clock @@ -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 |