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

Commit c725ece2 authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

[migrate_clocks_to_blueprint] Fix ordering of date+weather+alarm+dnd.

Flag: com.android.systemui.migrate_clocks_to_blueprint
Fix: 345575401
Test: on device, set an alarm and trigger dnd
Test: SmartspaceSectionTest
Change-Id: Ibd368e36d734dc9d61d5a08f014bf805a0176386
parent 67a15e86
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -121,10 +121,7 @@ object KeyguardSmartspaceViewBinder {
            ) {
                val dateView =
                    constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view)
                val weatherView =
                    constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view)
                addView(dateView)
                addView(weatherView)
            }
        }
    }
@@ -141,9 +138,6 @@ object KeyguardSmartspaceViewBinder {
            ) {
                val dateView =
                    constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view)
                val weatherView =
                    constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view)
                removeView(weatherView)
                removeView(dateView)
            }
        }
+10 −27
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.keyguard.ui.view.layout.sections

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver.OnGlobalLayoutListener
import androidx.constraintlayout.widget.Barrier
import androidx.constraintlayout.widget.ConstraintLayout
@@ -51,7 +52,7 @@ constructor(
) : KeyguardSection() {
    private var smartspaceView: View? = null
    private var weatherView: View? = null
    private var dateView: View? = null
    private var dateWeatherView: ViewGroup? = null

    private var smartspaceVisibilityListener: OnGlobalLayoutListener? = null
    private var pastVisibility: Int = -1
@@ -61,12 +62,15 @@ constructor(
        if (!keyguardSmartspaceViewModel.isSmartspaceEnabled) return
        smartspaceView = smartspaceController.buildAndConnectView(constraintLayout)
        weatherView = smartspaceController.buildAndConnectWeatherView(constraintLayout)
        dateView = smartspaceController.buildAndConnectDateView(constraintLayout)
        dateWeatherView =
            smartspaceController.buildAndConnectDateView(constraintLayout) as ViewGroup
        pastVisibility = smartspaceView?.visibility ?: View.GONE
        constraintLayout.addView(smartspaceView)
        if (keyguardSmartspaceViewModel.isDateWeatherDecoupled) {
            constraintLayout.addView(weatherView)
            constraintLayout.addView(dateView)
            constraintLayout.addView(dateWeatherView)
            // Place weather right after the date, before the extras (alarm and dnd)
            val index = if (dateWeatherView?.childCount == 0) 0 else 1
            dateWeatherView?.addView(weatherView, index)
        }
        keyguardUnlockAnimationController.lockscreenSmartspace = smartspaceView
        smartspaceVisibilityListener = OnGlobalLayoutListener {
@@ -108,26 +112,6 @@ constructor(
                ConstraintSet.START,
                horizontalPaddingStart
            )
            constrainWidth(sharedR.id.weather_smartspace_view, ConstraintSet.WRAP_CONTENT)
            connect(
                sharedR.id.weather_smartspace_view,
                ConstraintSet.TOP,
                sharedR.id.date_smartspace_view,
                ConstraintSet.TOP
            )
            connect(
                sharedR.id.weather_smartspace_view,
                ConstraintSet.BOTTOM,
                sharedR.id.date_smartspace_view,
                ConstraintSet.BOTTOM
            )
            connect(
                sharedR.id.weather_smartspace_view,
                ConstraintSet.START,
                sharedR.id.date_smartspace_view,
                ConstraintSet.END,
                4
            )

            // migrate addSmartspaceView from KeyguardClockSwitchController
            constrainHeight(sharedR.id.bc_smartspace_view, ConstraintSet.WRAP_CONTENT)
@@ -178,7 +162,6 @@ constructor(
                *intArrayOf(
                    sharedR.id.bc_smartspace_view,
                    sharedR.id.date_smartspace_view,
                    sharedR.id.weather_smartspace_view,
                )
            )
        }
@@ -188,7 +171,7 @@ constructor(
    override fun removeViews(constraintLayout: ConstraintLayout) {
        if (!MigrateClocksToBlueprint.isEnabled) return
        if (!keyguardSmartspaceViewModel.isSmartspaceEnabled) return
        listOf(smartspaceView, dateView, weatherView).forEach {
        listOf(smartspaceView, dateWeatherView).forEach {
            it?.let {
                if (it.parent == constraintLayout) {
                    constraintLayout.removeView(it)
@@ -212,7 +195,7 @@ constructor(
            setVisibility(sharedR.id.weather_smartspace_view, weatherVisibility)
            setAlpha(
                sharedR.id.weather_smartspace_view,
                if (weatherVisibility == ConstraintSet.VISIBLE) 1f else 0f
                if (weatherVisibility == View.VISIBLE) 1f else 0f
            )
            val dateVisibility =
                if (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) ConstraintSet.GONE
+4 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package com.android.systemui.keyguard.ui.view.layout.sections

import android.view.View
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.GONE
@@ -58,7 +59,7 @@ class SmartspaceSectionTest : SysuiTestCase() {

    private val smartspaceView = View(mContext).also { it.id = sharedR.id.bc_smartspace_view }
    private val weatherView = View(mContext).also { it.id = sharedR.id.weather_smartspace_view }
    private val dateView = View(mContext).also { it.id = sharedR.id.date_smartspace_view }
    private val dateView = LinearLayout(mContext).also { it.id = sharedR.id.date_smartspace_view }
    private lateinit var constraintLayout: ConstraintLayout
    private lateinit var constraintSet: ConstraintSet

@@ -109,7 +110,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
        whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
        underTest.addViews(constraintLayout)
        assert(smartspaceView.parent == constraintLayout)
        assert(weatherView.parent == constraintLayout)
        assertThat(weatherView.parent).isEqualTo(dateView)
        assert(dateView.parent == constraintLayout)
    }

@@ -127,7 +128,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
        whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
        underTest.addViews(constraintLayout)
        underTest.applyConstraints(constraintSet)
        assertWeatherSmartspaceConstrains(constraintSet)
        assertThat(weatherView.parent).isEqualTo(dateView)

        val smartspaceConstraints = constraintSet.getConstraint(smartspaceView.id)
        assertThat(smartspaceConstraints.layout.topToBottom).isEqualTo(dateView.id)
@@ -141,7 +142,6 @@ class SmartspaceSectionTest : SysuiTestCase() {
        hasCustomWeatherDataDisplay.value = true
        underTest.addViews(constraintLayout)
        underTest.applyConstraints(constraintSet)
        assertWeatherSmartspaceConstrains(constraintSet)

        val dateConstraints = constraintSet.getConstraint(dateView.id)
        assertThat(dateConstraints.layout.bottomToTop).isEqualTo(smartspaceView.id)
@@ -168,12 +168,4 @@ class SmartspaceSectionTest : SysuiTestCase() {
        assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(GONE)
        assertThat(constraintSet.getVisibility(dateView.id)).isEqualTo(GONE)
    }

    private fun assertWeatherSmartspaceConstrains(cs: ConstraintSet) {
        val weatherConstraints = cs.getConstraint(weatherView.id)
        assertThat(weatherConstraints.layout.topToTop).isEqualTo(dateView.id)
        assertThat(weatherConstraints.layout.bottomToBottom).isEqualTo(dateView.id)
        assertThat(weatherConstraints.layout.startToEnd).isEqualTo(dateView.id)
        assertThat(weatherConstraints.layout.startMargin).isEqualTo(4)
    }
}