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

Commit 0939e382 authored by Sherry Zhou's avatar Sherry Zhou Committed by Android (Google) Code Review
Browse files

Merge "Move cleaning up previous clock and assigning clock for...

Merge "Move cleaning up previous clock and assigning clock for clockEventController to KeyguardClockRepository when currentClock changes" into main
parents 6bcd2d9c 6346c42a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@ constructor(
        if (currentClock?.smallClock?.view == null) {
            return
        }
        viewModel.clock = currentClock

        val context = LocalContext.current
        MovableElement(key = smallClockElementKey, modifier = modifier) {
@@ -89,7 +88,6 @@ constructor(
    @Composable
    fun SceneScope.LargeClock(modifier: Modifier = Modifier) {
        val currentClock by viewModel.currentClock.collectAsState()
        viewModel.clock = currentClock
        if (currentClock?.largeClock?.view == null) {
            return
        }
+1 −1
Original line number Diff line number Diff line
@@ -631,7 +631,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
    @Nullable
    public ClockController getClock() {
        if (migrateClocksToBlueprint()) {
            return mKeyguardClockInteractor.getClock();
            return mKeyguardClockInteractor.getCurrentClock().getValue();
        } else {
            return mClockEventController.getClock();
        }
+4 −1
Original line number Diff line number Diff line
@@ -113,7 +113,10 @@ constructor(

    override val currentClock: StateFlow<ClockController?> =
        currentClockId
            .map { clockRegistry.createCurrentClock() }
            .map {
                clockEventController.clock = clockRegistry.createCurrentClock()
                clockEventController.clock
            }
            .stateIn(
                scope = applicationScope,
                started = SharingStarted.WhileSubscribed(),
+3 −2
Original line number Diff line number Diff line
@@ -213,9 +213,10 @@ constructor(
        cs: ConstraintSet,
        viewModel: KeyguardClockViewModel
    ) {
        if (!DEBUG || viewModel.clock == null) return
        val currentClock = viewModel.currentClock.value
        if (!DEBUG || currentClock == null) return
        val smallClockViewId = R.id.lockscreen_clock_view
        val largeClockViewId = viewModel.clock!!.largeClock.layout.views[0].id
        val largeClockViewId = currentClock.largeClock.layout.views[0].id
        Log.i(
            TAG,
            "applyCsToSmallClock: vis=${cs.getVisibility(smallClockViewId)} " +
+20 −7
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyguard.ui.binder
import android.transition.TransitionManager
import android.transition.TransitionSet
import android.view.View.INVISIBLE
import android.view.ViewGroup
import androidx.annotation.VisibleForTesting
import androidx.constraintlayout.helper.widget.Layer
import androidx.constraintlayout.widget.ConstraintLayout
@@ -40,7 +41,8 @@ import kotlinx.coroutines.launch

object KeyguardClockViewBinder {
    private val TAG = KeyguardClockViewBinder::class.simpleName!!

    // When changing to new clock, we need to remove old clock views from burnInLayer
    private var lastClock: ClockController? = null
    @JvmStatic
    fun bind(
        clockSection: ClockSection,
@@ -59,8 +61,7 @@ object KeyguardClockViewBinder {
                launch {
                    if (!migrateClocksToBlueprint()) return@launch
                    viewModel.currentClock.collect { currentClock ->
                        cleanupClockViews(viewModel.clock, keyguardRootView, viewModel.burnInLayer)
                        viewModel.clock = currentClock
                        cleanupClockViews(currentClock, keyguardRootView, viewModel.burnInLayer)
                        addClockViews(currentClock, keyguardRootView)
                        updateBurnInLayer(keyguardRootView, viewModel)
                        applyConstraints(clockSection, keyguardRootView, true)
@@ -76,7 +77,7 @@ object KeyguardClockViewBinder {
                launch {
                    if (!migrateClocksToBlueprint()) return@launch
                    viewModel.clockShouldBeCentered.collect { clockShouldBeCentered ->
                        viewModel.clock?.let {
                        viewModel.currentClock.value?.let {
                            // Weather clock also has hasCustomPositionUpdatedAnimation as true
                            // TODO(b/323020908): remove ID check
                            if (
@@ -93,7 +94,7 @@ object KeyguardClockViewBinder {
                launch {
                    if (!migrateClocksToBlueprint()) return@launch
                    viewModel.isAodIconsVisible.collect { isAodIconsVisible ->
                        viewModel.clock?.let {
                        viewModel.currentClock.value?.let {
                            // Weather clock also has hasCustomPositionUpdatedAnimation as true
                            if (
                                viewModel.useLargeClock && it.config.id == "DIGITAL_CLOCK_WEATHER"
@@ -132,11 +133,14 @@ object KeyguardClockViewBinder {
    }

    private fun cleanupClockViews(
        clockController: ClockController?,
        currentClock: ClockController?,
        rootView: ConstraintLayout,
        burnInLayer: Layer?
    ) {
        clockController?.let { clock ->
        if (lastClock == currentClock) {
            return
        }
        lastClock?.let { clock ->
            clock.smallClock.layout.views.forEach {
                burnInLayer?.removeView(it)
                rootView.removeView(it)
@@ -150,6 +154,7 @@ object KeyguardClockViewBinder {
            }
            clock.largeClock.layout.views.forEach { rootView.removeView(it) }
        }
        lastClock = currentClock
    }

    @VisibleForTesting
@@ -157,11 +162,19 @@ object KeyguardClockViewBinder {
        clockController: ClockController?,
        rootView: ConstraintLayout,
    ) {
        // We'll collect the same clock when exiting wallpaper picker without changing clock
        // so we need to remove clock views from parent before addView again
        clockController?.let { clock ->
            clock.smallClock.layout.views.forEach {
                if (it.parent != null) {
                    (it.parent as ViewGroup).removeView(it)
                }
                rootView.addView(it).apply { it.visibility = INVISIBLE }
            }
            clock.largeClock.layout.views.forEach {
                if (it.parent != null) {
                    (it.parent as ViewGroup).removeView(it)
                }
                rootView.addView(it).apply { it.visibility = INVISIBLE }
            }
        }
Loading