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

Commit c73a0439 authored by Brad Hinegardner's avatar Brad Hinegardner
Browse files

React to wide shade for date/weather move

We should fall below small clock if the shade is
wide and its half size is too small to show
date weather next to the small clock

Bug: 401274212
Test: atest KeyguardClockViewModelTest.kt
Flag: com.android.systemui.shared.clock_reactive_smartspace_layout
Change-Id: Ib5168f7d802c3706a1c2b953952befa2e0d2f939
parent 5234819d
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -109,7 +109,6 @@ class KeyguardBlueprintInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val blueprintId by collectLastValue(underTest.blueprintId)
            kosmos.shadeRepository.setShadeLayoutWide(true)
            clockRepository.setCurrentClock(clockController)
            configurationRepository.onConfigurationChange()

            runCurrent()
+3 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ class SmartspaceSectionTest : SysuiTestCase() {

    private val clockShouldBeCentered = MutableStateFlow(false)
    private val hasCustomWeatherDataDisplay = MutableStateFlow(false)
    private val shouldDateWeatherBeBelowSmallClock = MutableStateFlow(true)
    private val isWeatherVisibleFlow = MutableStateFlow(false)
    private val isShadeLayoutWide = MutableStateFlow(false)

@@ -95,6 +96,8 @@ class SmartspaceSectionTest : SysuiTestCase() {
            .thenReturn(dateView)
        whenever(keyguardClockViewModel.hasCustomWeatherDataDisplay)
            .thenReturn(hasCustomWeatherDataDisplay)
        whenever(keyguardClockViewModel.shouldDateWeatherBeBelowSmallClock)
            .thenReturn(shouldDateWeatherBeBelowSmallClock)
        whenever(keyguardClockViewModel.clockShouldBeCentered).thenReturn(clockShouldBeCentered)
        whenever(keyguardSmartspaceViewModel.isSmartspaceEnabled).thenReturn(true)
        whenever(keyguardSmartspaceViewModel.isWeatherVisible).thenReturn(isWeatherVisibleFlow)
+115 −0
Original line number Diff line number Diff line
@@ -16,9 +16,13 @@

package com.android.systemui.keyguard.ui.viewmodel

import android.content.res.Configuration
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
@@ -64,6 +68,8 @@ class KeyguardClockViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
    @Mock private lateinit var largeClock: ClockFaceController
    @Mock private lateinit var smallClock: ClockFaceController

    @Mock private lateinit var mockConfiguration: Configuration

    private var config = ClockConfig("TEST", "Test", "")
    private var faceConfig = ClockFaceConfig()

@@ -80,6 +86,7 @@ class KeyguardClockViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
        whenever(clockController.config).thenAnswer { config }
        whenever(largeClock.config).thenAnswer { faceConfig }
        whenever(smallClock.config).thenAnswer { faceConfig }
        kosmos.fakeConfigurationRepository.onConfigurationChange(mockConfiguration)
    }

    @Test
@@ -268,6 +275,114 @@ class KeyguardClockViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
            assertThat(underTest.getSmallClockTopMargin()).isEqualTo(expected)
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_smartspacelayoutflag_off_true() =
        testScope.runTest {
            val result by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)

            assertThat(result).isTrue()
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_defaultFontAndDisplaySize_shadeLayoutNotWide_false() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(false)
            val fontScale = 1.0f
            val screenWidthDp = 347
            mockConfiguration.fontScale = fontScale
            mockConfiguration.screenWidthDp = screenWidthDp

            val result by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)

            assertThat(result).isFalse()
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_shadeLayoutNotWide_false() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(false)
            mockConfiguration.fontScale = 1.0f
            mockConfiguration.screenWidthDp = 347
            val result1 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result1).isFalse()

            mockConfiguration.fontScale = 1.2f
            mockConfiguration.screenWidthDp = 347
            val result2 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result2).isFalse()

            mockConfiguration.fontScale = 1.7f
            mockConfiguration.screenWidthDp = 412
            val result3 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result3).isFalse()
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_shadeLayoutWide_false() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(true)
            mockConfiguration.fontScale = 1.0f
            mockConfiguration.screenWidthDp = 694
            val result1 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result1).isFalse()

            mockConfiguration.fontScale = 1.2f
            mockConfiguration.screenWidthDp = 694
            val result2 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result2).isFalse()

            mockConfiguration.fontScale = 1.7f
            mockConfiguration.screenWidthDp = 824
            val result3 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result3).isFalse()
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_shadeLayoutNotWide_true() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(false)
            mockConfiguration.fontScale = 1.0f
            mockConfiguration.screenWidthDp = 310
            val result1 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result1).isTrue()

            mockConfiguration.fontScale = 1.5f
            mockConfiguration.screenWidthDp = 347
            val result2 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result2).isTrue()

            mockConfiguration.fontScale = 2.0f
            mockConfiguration.screenWidthDp = 411
            val result3 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result3).isTrue()
        }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_shadeLayoutWide_true() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(true)
            mockConfiguration.fontScale = 1.0f
            mockConfiguration.screenWidthDp = 620
            val result1 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result1).isTrue()

            mockConfiguration.fontScale = 1.5f
            mockConfiguration.screenWidthDp = 694
            val result2 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result2).isTrue()

            mockConfiguration.fontScale = 2.0f
            mockConfiguration.screenWidthDp = 822
            val result3 by collectLastValue(underTest.shouldDateWeatherBeBelowSmallClock)
            assertThat(result3).isTrue()
        }

    companion object {
        private const val KEYGUARD_STATUS_BAR_HEIGHT = 20

+0 −71
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@

package com.android.systemui.keyguard.ui.viewmodel

import android.content.res.Configuration
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -47,7 +44,6 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val underTest = kosmos.keyguardSmartspaceViewModel
    @Mock private lateinit var mockConfiguration: Configuration

    @Mock(answer = Answers.RETURNS_DEEP_STUBS) private lateinit var clockController: ClockController

@@ -122,71 +118,4 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {
                assertThat(isShadeLayoutWide).isFalse()
            }
        }

    @Test
    @DisableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_smartspacelayoutflag_off_true() {
        val result =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)

        assertThat(result).isTrue()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_defaultFontAndDisplaySize_false() {
        val fontScale = 1.0f
        val screenWidthDp = 347
        mockConfiguration.fontScale = fontScale
        mockConfiguration.screenWidthDp = screenWidthDp

        val result =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)

        assertThat(result).isFalse()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_false() {
        mockConfiguration.fontScale = 1.0f
        mockConfiguration.screenWidthDp = 347
        val result1 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result1).isFalse()

        mockConfiguration.fontScale = 1.2f
        mockConfiguration.screenWidthDp = 347
        val result2 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result2).isFalse()

        mockConfiguration.fontScale = 1.7f
        mockConfiguration.screenWidthDp = 412
        val result3 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result3).isFalse()
    }

    @Test
    @EnableFlags(com.android.systemui.shared.Flags.FLAG_CLOCK_REACTIVE_SMARTSPACE_LAYOUT)
    fun dateWeatherBelowSmallClock_variousFontAndDisplaySize_true() {
        mockConfiguration.fontScale = 1.0f
        mockConfiguration.screenWidthDp = 310
        val result1 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result1).isTrue()

        mockConfiguration.fontScale = 1.5f
        mockConfiguration.screenWidthDp = 347
        val result2 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result2).isTrue()

        mockConfiguration.fontScale = 2.0f
        mockConfiguration.screenWidthDp = 411
        val result3 =
            KeyguardSmartspaceViewModel.dateWeatherBelowSmallClock(mockConfiguration, false)
        assertThat(result3).isTrue()
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -143,7 +143,9 @@ object KeyguardSmartspaceViewBinder {
                                        view.top = (clockBounds.bottom + yBuffer + offset).toInt()
                                        view.bottom = view.top + viewHeight
                                    }
                                } else if (!clockViewModel.dateWeatherBelowSmallClock()) {
                                } else if (
                                    !clockViewModel.shouldDateWeatherBeBelowSmallClock.value
                                ) {
                                    keyguardRootView.findViewById<View>(smallViewId)?.let { view ->
                                        val viewWidth = view.width
                                        if (view.isLayoutRtl()) {
Loading