Loading packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt +5 −4 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ interface KeyguardClockRepository { val currentClock: StateFlow<ClockController?> val previewClock: StateFlow<ClockController> val previewClockPair: StateFlow<Pair<ClockController, ClockController>> val clockEventController: ClockEventController fun setClockSize(@ClockSize size: Int) Loading Loading @@ -120,13 +120,14 @@ constructor( initialValue = clockRegistry.createCurrentClock() ) override val previewClock: StateFlow<ClockController> = override val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = currentClockId .map { clockRegistry.createCurrentClock() } .map { Pair(clockRegistry.createCurrentClock(), clockRegistry.createCurrentClock()) } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = clockRegistry.createCurrentClock() initialValue = Pair(clockRegistry.createCurrentClock(), clockRegistry.createCurrentClock()) ) @VisibleForTesting Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ constructor( val currentClock: StateFlow<ClockController?> = keyguardClockRepository.currentClock val previewClock: StateFlow<ClockController> = keyguardClockRepository.previewClock val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = keyguardClockRepository.previewClockPair var clock: ClockController? by keyguardClockRepository.clockEventController::clock Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt +31 −18 Original line number Diff line number Diff line Loading @@ -72,38 +72,47 @@ object KeyguardPreviewClockViewBinder { @JvmStatic fun bind( context: Context, displayId: Int, rootView: ConstraintLayout, viewModel: KeyguardPreviewClockViewModel, clockEventController: ClockEventController, updateClockAppearance: KSuspendFunction1<ClockController, Unit> updateClockAppearance: KSuspendFunction1<ClockController, Unit>, ) { // TODO(b/327668072): When this function is called multiple times, the clock view can be // gone due to a race condition on removeView and addView. rootView.repeatWhenAttached { repeatOnLifecycle(Lifecycle.State.STARTED) { launch { combine(viewModel.selectedClockSize, viewModel.previewClock) { _, clock -> combine(viewModel.selectedClockSize, viewModel.previewClockPair) { _, clock -> clock } .collect { previewClock -> viewModel.lastClock?.let { lastClock -> (lastClock.largeClock.layout.views + lastClock.smallClock.layout.views) .collect { previewClockPair -> viewModel.lastClockPair?.let { clockPair -> (clockPair.first.largeClock.layout.views + clockPair.first.smallClock.layout.views) .forEach { rootView.removeView(it) } (clockPair.second.largeClock.layout.views + clockPair.second.smallClock.layout.views) .forEach { rootView.removeView(it) } } viewModel.lastClock = previewClock clockEventController.clock = previewClock updateClockAppearance(previewClock) viewModel.lastClockPair = previewClockPair val clockPreview = if (displayId == 0) previewClockPair.first else previewClockPair.second clockEventController.clock = clockPreview updateClockAppearance(clockPreview) if (viewModel.shouldHighlightSelectedAffordance) { (previewClock.largeClock.layout.views + previewClock.smallClock.layout.views) (clockPreview.largeClock.layout.views + clockPreview.smallClock.layout.views) .forEach { it.alpha = KeyguardPreviewRenderer.DIM_ALPHA } } previewClock.largeClock.layout.views.forEach { clockPreview.largeClock.layout.views.forEach { (it.parent as? ViewGroup)?.removeView(it) rootView.addView(it) } previewClock.smallClock.layout.views.forEach { clockPreview.smallClock.layout.views.forEach { (it.parent as? ViewGroup)?.removeView(it) rootView.addView(it) } Loading Loading @@ -164,10 +173,12 @@ object KeyguardPreviewClockViewBinder { viewModel: KeyguardPreviewClockViewModel ) { val cs = ConstraintSet().apply { clone(rootView) } val clock = viewModel.previewClock.value val clockPair = viewModel.previewClockPair.value applyClockDefaultConstraints(context, cs) clock.largeClock.layout.applyPreviewConstraints(cs) clock.smallClock.layout.applyPreviewConstraints(cs) clockPair.first.largeClock.layout.applyPreviewConstraints(cs) clockPair.first.smallClock.layout.applyPreviewConstraints(cs) clockPair.second.largeClock.layout.applyPreviewConstraints(cs) clockPair.second.smallClock.layout.applyPreviewConstraints(cs) // When selectedClockSize is the initial value, make both clocks invisible to avoid // flickering Loading @@ -185,8 +196,10 @@ object KeyguardPreviewClockViewBinder { } cs.apply { setVisibility(clock.largeClock.layout.views, largeClockVisibility) setVisibility(clock.smallClock.layout.views, smallClockVisibility) setVisibility(clockPair.first.largeClock.layout.views, largeClockVisibility) setVisibility(clockPair.first.smallClock.layout.views, smallClockVisibility) setVisibility(clockPair.second.largeClock.layout.views, largeClockVisibility) setVisibility(clockPair.second.smallClock.layout.views, smallClockVisibility) } cs.applyTo(rootView) } Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt +1 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,7 @@ constructor( if (migrateClocksToBlueprint()) { KeyguardPreviewClockViewBinder.bind( context, displayId, keyguardRootView, clockViewModel, clockController, Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt +3 −2 Original line number Diff line number Diff line Loading @@ -45,9 +45,10 @@ constructor( val isSmallClockVisible: Flow<Boolean> = interactor.selectedClockSize.map { it == SettingsClockSize.SMALL } var lastClock: ClockController? = null var lastClockPair: Pair<ClockController, ClockController>? = null val previewClock: StateFlow<ClockController> = interactor.previewClock val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = interactor.previewClockPair val selectedClockSize: StateFlow<SettingsClockSize?> = interactor.selectedClockSize.stateIn( Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardClockRepository.kt +5 −4 Original line number Diff line number Diff line Loading @@ -59,7 +59,7 @@ interface KeyguardClockRepository { val currentClock: StateFlow<ClockController?> val previewClock: StateFlow<ClockController> val previewClockPair: StateFlow<Pair<ClockController, ClockController>> val clockEventController: ClockEventController fun setClockSize(@ClockSize size: Int) Loading Loading @@ -120,13 +120,14 @@ constructor( initialValue = clockRegistry.createCurrentClock() ) override val previewClock: StateFlow<ClockController> = override val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = currentClockId .map { clockRegistry.createCurrentClock() } .map { Pair(clockRegistry.createCurrentClock(), clockRegistry.createCurrentClock()) } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = clockRegistry.createCurrentClock() initialValue = Pair(clockRegistry.createCurrentClock(), clockRegistry.createCurrentClock()) ) @VisibleForTesting Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardClockInteractor.kt +2 −1 Original line number Diff line number Diff line Loading @@ -44,7 +44,8 @@ constructor( val currentClock: StateFlow<ClockController?> = keyguardClockRepository.currentClock val previewClock: StateFlow<ClockController> = keyguardClockRepository.previewClock val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = keyguardClockRepository.previewClockPair var clock: ClockController? by keyguardClockRepository.clockEventController::clock Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardPreviewClockViewBinder.kt +31 −18 Original line number Diff line number Diff line Loading @@ -72,38 +72,47 @@ object KeyguardPreviewClockViewBinder { @JvmStatic fun bind( context: Context, displayId: Int, rootView: ConstraintLayout, viewModel: KeyguardPreviewClockViewModel, clockEventController: ClockEventController, updateClockAppearance: KSuspendFunction1<ClockController, Unit> updateClockAppearance: KSuspendFunction1<ClockController, Unit>, ) { // TODO(b/327668072): When this function is called multiple times, the clock view can be // gone due to a race condition on removeView and addView. rootView.repeatWhenAttached { repeatOnLifecycle(Lifecycle.State.STARTED) { launch { combine(viewModel.selectedClockSize, viewModel.previewClock) { _, clock -> combine(viewModel.selectedClockSize, viewModel.previewClockPair) { _, clock -> clock } .collect { previewClock -> viewModel.lastClock?.let { lastClock -> (lastClock.largeClock.layout.views + lastClock.smallClock.layout.views) .collect { previewClockPair -> viewModel.lastClockPair?.let { clockPair -> (clockPair.first.largeClock.layout.views + clockPair.first.smallClock.layout.views) .forEach { rootView.removeView(it) } (clockPair.second.largeClock.layout.views + clockPair.second.smallClock.layout.views) .forEach { rootView.removeView(it) } } viewModel.lastClock = previewClock clockEventController.clock = previewClock updateClockAppearance(previewClock) viewModel.lastClockPair = previewClockPair val clockPreview = if (displayId == 0) previewClockPair.first else previewClockPair.second clockEventController.clock = clockPreview updateClockAppearance(clockPreview) if (viewModel.shouldHighlightSelectedAffordance) { (previewClock.largeClock.layout.views + previewClock.smallClock.layout.views) (clockPreview.largeClock.layout.views + clockPreview.smallClock.layout.views) .forEach { it.alpha = KeyguardPreviewRenderer.DIM_ALPHA } } previewClock.largeClock.layout.views.forEach { clockPreview.largeClock.layout.views.forEach { (it.parent as? ViewGroup)?.removeView(it) rootView.addView(it) } previewClock.smallClock.layout.views.forEach { clockPreview.smallClock.layout.views.forEach { (it.parent as? ViewGroup)?.removeView(it) rootView.addView(it) } Loading Loading @@ -164,10 +173,12 @@ object KeyguardPreviewClockViewBinder { viewModel: KeyguardPreviewClockViewModel ) { val cs = ConstraintSet().apply { clone(rootView) } val clock = viewModel.previewClock.value val clockPair = viewModel.previewClockPair.value applyClockDefaultConstraints(context, cs) clock.largeClock.layout.applyPreviewConstraints(cs) clock.smallClock.layout.applyPreviewConstraints(cs) clockPair.first.largeClock.layout.applyPreviewConstraints(cs) clockPair.first.smallClock.layout.applyPreviewConstraints(cs) clockPair.second.largeClock.layout.applyPreviewConstraints(cs) clockPair.second.smallClock.layout.applyPreviewConstraints(cs) // When selectedClockSize is the initial value, make both clocks invisible to avoid // flickering Loading @@ -185,8 +196,10 @@ object KeyguardPreviewClockViewBinder { } cs.apply { setVisibility(clock.largeClock.layout.views, largeClockVisibility) setVisibility(clock.smallClock.layout.views, smallClockVisibility) setVisibility(clockPair.first.largeClock.layout.views, largeClockVisibility) setVisibility(clockPair.first.smallClock.layout.views, smallClockVisibility) setVisibility(clockPair.second.largeClock.layout.views, largeClockVisibility) setVisibility(clockPair.second.smallClock.layout.views, smallClockVisibility) } cs.applyTo(rootView) } Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt +1 −0 Original line number Diff line number Diff line Loading @@ -408,6 +408,7 @@ constructor( if (migrateClocksToBlueprint()) { KeyguardPreviewClockViewBinder.bind( context, displayId, keyguardRootView, clockViewModel, clockController, Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardPreviewClockViewModel.kt +3 −2 Original line number Diff line number Diff line Loading @@ -45,9 +45,10 @@ constructor( val isSmallClockVisible: Flow<Boolean> = interactor.selectedClockSize.map { it == SettingsClockSize.SMALL } var lastClock: ClockController? = null var lastClockPair: Pair<ClockController, ClockController>? = null val previewClock: StateFlow<ClockController> = interactor.previewClock val previewClockPair: StateFlow<Pair<ClockController, ClockController>> = interactor.previewClockPair val selectedClockSize: StateFlow<SettingsClockSize?> = interactor.selectedClockSize.stateIn( Loading