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

Commit bf054436 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix keyguard clock view missing" into main

parents 91e1dc47 57331ef0
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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)
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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

+31 −18
Original line number Diff line number Diff line
@@ -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)
                            }
@@ -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
@@ -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)
    }
+1 −0
Original line number Diff line number Diff line
@@ -408,6 +408,7 @@ constructor(
            if (migrateClocksToBlueprint()) {
                KeyguardPreviewClockViewBinder.bind(
                    context,
                    displayId,
                    keyguardRootView,
                    clockViewModel,
                    clockController,
+3 −2
Original line number Diff line number Diff line
@@ -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