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

Commit f9525c43 authored by Xiaowen Lei's avatar Xiaowen Lei Committed by Android (Google) Code Review
Browse files

Merge "Constrain Lockscreen smartspace to half screen for wide shade layout." into main

parents d91cbe8c b2b716e3
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteract
import com.android.systemui.keyguard.domain.interactor.KeyguardSmartspaceInteractor
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
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
@@ -68,6 +69,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
    private val clockShouldBeCentered = MutableStateFlow(false)
    private val hasCustomWeatherDataDisplay = MutableStateFlow(false)
    private val isWeatherVisibleFlow = MutableStateFlow(false)
    private val isShadeLayoutWide = MutableStateFlow(false)

    @Before
    fun setup() {
@@ -80,7 +82,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
                keyguardSmartspaceInteractor,
                lockscreenSmartspaceController,
                keyguardUnlockAnimationController,
                blueprintInteractor
                blueprintInteractor,
            )
        constraintLayout = ConstraintLayout(mContext)
        whenever(lockscreenSmartspaceController.buildAndConnectView(any()))
@@ -93,6 +95,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
        whenever(keyguardClockViewModel.clockShouldBeCentered).thenReturn(clockShouldBeCentered)
        whenever(keyguardSmartspaceViewModel.isSmartspaceEnabled).thenReturn(true)
        whenever(keyguardSmartspaceViewModel.isWeatherVisible).thenReturn(isWeatherVisibleFlow)
        whenever(keyguardSmartspaceViewModel.isShadeLayoutWide).thenReturn(isShadeLayoutWide)
        constraintSet = ConstraintSet()
    }

@@ -124,6 +127,26 @@ class SmartspaceSectionTest : SysuiTestCase() {
        assert(dateView.parent == null)
    }

    @Test
    fun testConstraintsWhenShadeLayoutIsNotWide() {
        underTest.addViews(constraintLayout)
        underTest.applyConstraints(constraintSet)

        val smartspaceConstraints = constraintSet.getConstraint(smartspaceView.id)
        assertThat(smartspaceConstraints.layout.endToEnd).isEqualTo(ConstraintSet.PARENT_ID)
    }

    @Test
    fun testConstraintsWhenShadeLayoutIsWide() {
        isShadeLayoutWide.value = true

        underTest.addViews(constraintLayout)
        underTest.applyConstraints(constraintSet)

        val smartspaceConstraints = constraintSet.getConstraint(smartspaceView.id)
        assertThat(smartspaceConstraints.layout.endToEnd).isEqualTo(R.id.split_shade_guideline)
    }

    @Test
    fun testConstraintsWhenNotHasCustomWeatherDataDisplay() {
        whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
@@ -160,6 +183,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
        assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(GONE)
        assertThat(constraintSet.getVisibility(dateView.id)).isEqualTo(VISIBLE)
    }

    @Test
    fun testCustomDateWeatherVisibility() {
        hasCustomWeatherDataDisplay.value = true
+23 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.keyguard.data.repository.keyguardSmartspaceRepositor
import com.android.systemui.keyguard.shared.model.ClockSize
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.shade.data.repository.shadeRepository
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
@@ -96,4 +97,26 @@ class KeyguardSmartspaceViewModelTest : SysuiTestCase() {

            assertThat(isWeatherVisible).isEqualTo(false)
        }

    @Test
    fun isShadeLayoutWide_withConfigTrue_true() =
        with(kosmos) {
            testScope.runTest {
                val isShadeLayoutWide by collectLastValue(underTest.isShadeLayoutWide)
                shadeRepository.setShadeLayoutWide(true)

                assertThat(isShadeLayoutWide).isTrue()
            }
        }

    @Test
    fun isShadeLayoutWide_withConfigFalse_false() =
        with(kosmos) {
            testScope.runTest {
                val isShadeLayoutWide by collectLastValue(underTest.isShadeLayoutWide)
                shadeRepository.setShadeLayoutWide(false)

                assertThat(isShadeLayoutWide).isFalse()
            }
        }
}
+11 −14
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ constructor(
                ConstraintSet.START,
                ConstraintSet.PARENT_ID,
                ConstraintSet.START,
                horizontalPaddingStart
                horizontalPaddingStart,
            )

            // migrate addSmartspaceView from KeyguardClockSwitchController
@@ -135,15 +135,15 @@ constructor(
                ConstraintSet.START,
                ConstraintSet.PARENT_ID,
                ConstraintSet.START,
                horizontalPaddingStart
                horizontalPaddingStart,
            )
            connect(
                sharedR.id.bc_smartspace_view,
                ConstraintSet.END,
                if (keyguardClockViewModel.clockShouldBeCentered.value) ConstraintSet.PARENT_ID
                else R.id.split_shade_guideline,
                if (keyguardSmartspaceViewModel.isShadeLayoutWide.value) R.id.split_shade_guideline
                else ConstraintSet.PARENT_ID,
                ConstraintSet.END,
                horizontalPaddingEnd
                horizontalPaddingEnd,
            )

            if (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) {
@@ -152,7 +152,7 @@ constructor(
                    sharedR.id.date_smartspace_view,
                    ConstraintSet.BOTTOM,
                    sharedR.id.bc_smartspace_view,
                    ConstraintSet.TOP
                    ConstraintSet.TOP,
                )
            } else {
                clear(sharedR.id.date_smartspace_view, ConstraintSet.BOTTOM)
@@ -160,13 +160,13 @@ constructor(
                    sharedR.id.date_smartspace_view,
                    ConstraintSet.TOP,
                    customR.id.lockscreen_clock_view,
                    ConstraintSet.BOTTOM
                    ConstraintSet.BOTTOM,
                )
                connect(
                    sharedR.id.bc_smartspace_view,
                    ConstraintSet.TOP,
                    sharedR.id.date_smartspace_view,
                    ConstraintSet.BOTTOM
                    ConstraintSet.BOTTOM,
                )
            }

@@ -174,10 +174,7 @@ constructor(
                R.id.smart_space_barrier_bottom,
                Barrier.BOTTOM,
                0,
                *intArrayOf(
                    sharedR.id.bc_smartspace_view,
                    sharedR.id.date_smartspace_view,
                )
                *intArrayOf(sharedR.id.bc_smartspace_view, sharedR.id.date_smartspace_view),
            )
        }
        updateVisibility(constraintSet)
@@ -212,7 +209,7 @@ constructor(
            setVisibility(sharedR.id.weather_smartspace_view, weatherVisibility)
            setAlpha(
                sharedR.id.weather_smartspace_view,
                if (weatherVisibility == View.VISIBLE) 1f else 0f
                if (weatherVisibility == View.VISIBLE) 1f else 0f,
            )
            val dateVisibility =
                if (keyguardClockViewModel.hasCustomWeatherDataDisplay.value) ConstraintSet.GONE
@@ -220,7 +217,7 @@ constructor(
            setVisibility(sharedR.id.date_smartspace_view, dateVisibility)
            setAlpha(
                sharedR.id.date_smartspace_view,
                if (dateVisibility == ConstraintSet.VISIBLE) 1f else 0f
                if (dateVisibility == ConstraintSet.VISIBLE) 1f else 0f,
            )
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardSmartspaceInteractor
import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
@@ -39,6 +40,7 @@ constructor(
    smartspaceController: LockscreenSmartspaceController,
    keyguardClockViewModel: KeyguardClockViewModel,
    smartspaceInteractor: KeyguardSmartspaceInteractor,
    shadeInteractor: ShadeInteractor,
) {
    /** Whether the smartspace section is available in the build. */
    val isSmartspaceEnabled: Boolean = smartspaceController.isEnabled
@@ -89,6 +91,8 @@ constructor(
    /* trigger clock and smartspace constraints change when smartspace appears */
    val bcSmartspaceVisibility: StateFlow<Int> = smartspaceInteractor.bcSmartspaceVisibility

    val isShadeLayoutWide: StateFlow<Boolean> = shadeInteractor.isShadeLayoutWide

    companion object {
        fun getSmartspaceStartMargin(context: Context): Int {
            return context.resources.getDimensionPixelSize(R.dimen.below_clock_padding_start) +
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyguard.ui.viewmodel
import com.android.systemui.keyguard.domain.interactor.keyguardSmartspaceInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.util.mockito.mock

val Kosmos.keyguardSmartspaceViewModel by
@@ -28,5 +29,6 @@ val Kosmos.keyguardSmartspaceViewModel by
            smartspaceController = mock(),
            keyguardClockViewModel = keyguardClockViewModel,
            smartspaceInteractor = keyguardSmartspaceInteractor,
            shadeInteractor = shadeInteractor,
        )
    }