summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2025-02-24 11:05:50 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-02-24 11:05:50 -0800
commit0df1c851ba7303f8224aa422dcd5287f927acd91 (patch)
treefffed6c42389684178cfdc8a54b067147ea475a1
parent942a581d9f07ad342092523a20aacd24186a1f98 (diff)
parent2fb3500da9e618979e7b46dfed791ba962f691cd (diff)
Merge "Update keyguard preview when clock size setting changes" into main
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt69
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