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

Commit 3a6eef02 authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

Small date and weather should always be below small weather clock

Bug: 409530972
Test: atest KeyguardSmartspaceViewModelTest.kt
Flag: com.android.systemui.shared.clock_reactive_smartspace_layout
Change-Id: Id9ef96c5d8d51b9612932bcc6304a2c01c233e55
parent 6cab89d2
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -37,8 +37,6 @@ import com.android.systemui.plugins.clocks.ClockViewIds
import com.android.systemui.res.R
import com.android.systemui.shared.R as sharedR
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import dagger.Lazy
import kotlinx.coroutines.flow.MutableStateFlow
@@ -47,6 +45,8 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
@SmallTest
@@ -72,6 +72,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
    private val shouldDateWeatherBeBelowSmallClock = MutableStateFlow(true)
    private val isWeatherVisibleFlow = MutableStateFlow(false)
    private val isShadeLayoutWide = MutableStateFlow(false)
    private val isLargeClockVisible = MutableStateFlow(true)

    @Before
    fun setup() {
@@ -96,6 +97,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
            .thenReturn(dateView)
        whenever(keyguardClockViewModel.hasCustomWeatherDataDisplay)
            .thenReturn(hasCustomWeatherDataDisplay)
        whenever(keyguardClockViewModel.isLargeClockVisible).thenReturn(isLargeClockVisible)
        whenever(keyguardClockViewModel.shouldDateWeatherBeBelowSmallClock)
            .thenReturn(shouldDateWeatherBeBelowSmallClock)
        whenever(keyguardClockViewModel.clockShouldBeCentered).thenReturn(clockShouldBeCentered)
+85 −0
Original line number Diff line number Diff line
@@ -68,6 +68,21 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
            assertThat(isWeatherVisible).isEqualTo(true)
        }

    @Test
    fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_isWeatherVisible_smallClock_shouldBeTrue() =
        testScope.runTest {
            val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
            whenever(clockController.smallClock.config.hasCustomWeatherDataDisplay)
                .thenReturn(false)

            with(kosmos) {
                keyguardSmartspaceRepository.setIsWeatherEnabled(true)
                keyguardClockRepository.setClockSize(ClockSize.SMALL)
            }

            assertThat(isWeatherVisible).isEqualTo(true)
        }

    @Test
    fun testWhenWeatherEnabled_hasCustomWeatherDataDisplay_isWeatherVisible_shouldBeFalse() =
        testScope.runTest {
@@ -82,6 +97,20 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
            assertThat(isWeatherVisible).isEqualTo(false)
        }

    @Test
    fun testWhenWeatherEnabled_hasCustomWeatherDataDisplay_isWeatherVisible_smallClock_shouldBeTrue() =
        testScope.runTest {
            val isWeatherVisible by collectLastValue(underTest.isWeatherVisible)
            whenever(clockController.smallClock.config.hasCustomWeatherDataDisplay).thenReturn(true)

            with(kosmos) {
                keyguardSmartspaceRepository.setIsWeatherEnabled(true)
                keyguardClockRepository.setClockSize(ClockSize.SMALL)
            }

            assertThat(isWeatherVisible).isEqualTo(true)
        }

    @Test
    fun testWhenWeatherEnabled_notCustomWeatherDataDisplay_notIsWeatherVisible_shouldBeFalse() =
        testScope.runTest {
@@ -97,6 +126,62 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
            assertThat(isWeatherVisible).isEqualTo(false)
        }

    @Test
    fun isDateVisible_notCustomWeatherDataDisplay_largeClock_shouldBeTrue() =
        testScope.runTest {
            val isDateVisible by collectLastValue(underTest.isDateVisible)
            whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
                .thenReturn(false)

            with(kosmos) {
                keyguardClockRepository.setClockSize(ClockSize.LARGE)
            }

            assertThat(isDateVisible).isEqualTo(true)
        }

    @Test
    fun isDateVisible_hasCustomWeatherDataDisplay_largeClock_shouldBeFalse() =
        testScope.runTest {
            val isDateVisible by collectLastValue(underTest.isDateVisible)
            whenever(clockController.largeClock.config.hasCustomWeatherDataDisplay)
                .thenReturn(true)

            with(kosmos) {
                keyguardClockRepository.setClockSize(ClockSize.LARGE)
            }

            assertThat(isDateVisible).isEqualTo(false)
        }

    @Test
    fun isDateVisible_hasCustomWeatherDataDisplay_smallClock_shouldBeTrue() =
        testScope.runTest {
            val isDateVisible by collectLastValue(underTest.isDateVisible)
            whenever(clockController.smallClock.config.hasCustomWeatherDataDisplay)
                .thenReturn(true)

            with(kosmos) {
                keyguardClockRepository.setClockSize(ClockSize.SMALL)
            }

            assertThat(isDateVisible).isEqualTo(true)
        }

    @Test
    fun isDateVisible_notCustomWeatherDataDisplay_smallClock_shouldBeTrue() =
        testScope.runTest {
            val isDateVisible by collectLastValue(underTest.isDateVisible)
            whenever(clockController.smallClock.config.hasCustomWeatherDataDisplay)
                .thenReturn(false)

            with(kosmos) {
                keyguardClockRepository.setClockSize(ClockSize.SMALL)
            }

            assertThat(isDateVisible).isEqualTo(true)
        }

    @Test
    fun isShadeLayoutWide_withConfigTrue_true() =
        with(kosmos) {
+17 −24
Original line number Diff line number Diff line
@@ -53,7 +53,9 @@ object KeyguardSmartspaceViewBinder {
                            ::Pair,
                        )
                        .collect {
                            if (!com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                            if (
                                !com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()
                            ) {
                                updateDateWeatherToBurnInLayer(
                                    keyguardRootView,
                                    clockViewModel,
@@ -97,15 +99,9 @@ object KeyguardSmartspaceViewBinder {

                    val largeViewId = sharedR.id.date_smartspace_view_large

                    launch("$TAG#smartspaceViewModel.burnInLayerVisibility") {
                        combine(
                                keyguardRootViewModel.burnInLayerVisibility,
                                clockViewModel.isLargeClockVisible,
                                clockViewModel.hasCustomWeatherDataDisplay,
                                ::Triple,
                            )
                            .collect { (visibility, isLargeClock, hasCustomWeatherDataDisplay) ->
                                if (isLargeClock || hasCustomWeatherDataDisplay) {
                    launch("$TAG#smartspaceViewModel.isLargeClockVisible") {
                        clockViewModel.isLargeClockVisible.collect { isLargeClock ->
                            if (isLargeClock) {
                                // hide small clock date/weather
                                keyguardRootView.findViewById<View>(smallViewId)?.let {
                                    it.visibility = View.GONE
@@ -115,10 +111,7 @@ object KeyguardSmartspaceViewBinder {
                                    smartspaceViewModel,
                                )
                            } else {
                                    addDateWeatherToBurnInLayer(
                                        keyguardRootView,
                                        smartspaceViewModel,
                                    )
                                addDateWeatherToBurnInLayer(keyguardRootView, smartspaceViewModel)
                            }
                            clockViewModel.burnInLayer?.updatePostLayout(keyguardRootView)
                        }
+17 −17
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
import com.android.systemui.plugins.clocks.ClockViewIds
import com.android.systemui.res.R as R
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout
import com.android.systemui.shared.R as sharedR
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import dagger.Lazy
@@ -80,7 +81,7 @@ constructor(
            smartspaceController.buildAndConnectDateView(constraintLayout, false) as? LinearLayout
        pastVisibility = smartspaceView?.visibility ?: View.GONE
        constraintLayout.addView(smartspaceView)
        if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
        if (clockReactiveSmartspaceLayout()) {
            val weatherViewLargeClock =
                smartspaceController.buildAndConnectWeatherView(constraintLayout, true)
            dateViewLargeClock =
@@ -136,7 +137,8 @@ constructor(
            KeyguardSmartspaceViewModel.getSmartspaceHorizontalMargin(context)
        val dateWeatherBelowSmallClock =
            keyguardClockViewModel.shouldDateWeatherBeBelowSmallClock.value
        if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
        val isLargeClockVisible = keyguardClockViewModel.isLargeClockVisible.value
        if (clockReactiveSmartspaceLayout()) {
            if (dateWeatherBelowSmallClock) {
                dateView?.orientation = LinearLayout.HORIZONTAL
            } else {
@@ -173,7 +175,7 @@ constructor(
                ConstraintSet.END,
                smartspaceHorizontalPadding,
            )
            if (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) {
            if (keyguardClockViewModel.hasCustomWeatherDataDisplay.value && isLargeClockVisible) {
                clear(sharedR.id.date_smartspace_view, ConstraintSet.TOP)
                connect(
                    sharedR.id.date_smartspace_view,
@@ -183,7 +185,7 @@ constructor(
                )
            } else {
                clear(sharedR.id.date_smartspace_view, ConstraintSet.BOTTOM)
                if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                if (clockReactiveSmartspaceLayout()) {
                    if (dateWeatherBelowSmallClock) {
                        connect(
                            sharedR.id.date_smartspace_view,
@@ -221,8 +223,8 @@ constructor(
                }
            }

            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                if (keyguardClockViewModel.isLargeClockVisible.value) {
            if (clockReactiveSmartspaceLayout()) {
                if (isLargeClockVisible) {
                    setVisibility(sharedR.id.date_smartspace_view, GONE)
                    constrainHeight(
                        sharedR.id.date_smartspace_view_large,
@@ -302,7 +304,7 @@ constructor(
                }
            }

            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
            if (clockReactiveSmartspaceLayout()) {
                if (dateWeatherBelowSmallClock) {
                    createBarrier(
                        R.id.smart_space_barrier_bottom,
@@ -345,14 +347,14 @@ constructor(
                )
            }
        }
        updateVisibility(constraintSet)
        updateVisibility(constraintSet, isLargeClockVisible)
    }

    override fun removeViews(constraintLayout: ConstraintLayout) {
        if (!keyguardSmartspaceViewModel.isSmartspaceEnabled) return

        val list =
            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
            if (clockReactiveSmartspaceLayout()) {
                listOf(smartspaceView, dateView, dateViewLargeClock)
            } else {
                listOf(smartspaceView, dateView)
@@ -370,16 +372,13 @@ constructor(
        disposableHandle?.dispose()
    }

    private fun updateVisibility(constraintSet: ConstraintSet) {
    private fun updateVisibility(constraintSet: ConstraintSet, isLargeClockVisible: Boolean) {

        // This may update the visibility of the smartspace views
        smartspaceController.requestSmartspaceUpdate()
        val weatherId: Int
        val dateId: Int
        if (
            com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout() &&
                keyguardClockViewModel.isLargeClockVisible.value
        ) {
        if (clockReactiveSmartspaceLayout() && isLargeClockVisible) {
            weatherId = sharedR.id.weather_smartspace_view_large
            dateId = sharedR.id.date_smartspace_view_large
        } else {
@@ -392,12 +391,13 @@ constructor(
            setVisibility(weatherId, if (showWeather) VISIBLE else GONE)
            setAlpha(weatherId, if (showWeather) 1f else 0f)

            val showDateView = !keyguardClockViewModel.hasCustomWeatherDataDisplay.value
            val showDateView =
                !keyguardClockViewModel.hasCustomWeatherDataDisplay.value || !isLargeClockVisible
            setVisibility(dateId, if (showDateView) VISIBLE else GONE)
            setAlpha(dateId, if (showDateView) 1f else 0f)

            if (com.android.systemui.shared.Flags.clockReactiveSmartspaceLayout()) {
                if (keyguardClockViewModel.isLargeClockVisible.value) {
            if (clockReactiveSmartspaceLayout()) {
                if (isLargeClockVisible) {
                    setVisibility(sharedR.id.date_smartspace_view, GONE)
                } else {
                    setVisibility(sharedR.id.date_smartspace_view_large, GONE)
+1 −1
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ class ClockSizeTransition(

        override fun mutateTargets(from: Target, to: Target) {
            if (to.view.id == sharedR.id.date_smartspace_view) {
                to.isVisible = !viewModel.hasCustomWeatherDataDisplay.value
                to.isVisible = !viewModel.hasCustomWeatherDataDisplay.value || !isLargeClock
                to.visibility = if (to.isVisible) View.VISIBLE else View.GONE
                to.alpha = if (to.isVisible) 1f else 0f
            }
Loading