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 Original line 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.domain.interactor.KeyguardSmartspaceInteractor
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel
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.shared.R as sharedR
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.any
@@ -68,6 +69,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
    private val clockShouldBeCentered = MutableStateFlow(false)
    private val clockShouldBeCentered = MutableStateFlow(false)
    private val hasCustomWeatherDataDisplay = MutableStateFlow(false)
    private val hasCustomWeatherDataDisplay = MutableStateFlow(false)
    private val isWeatherVisibleFlow = MutableStateFlow(false)
    private val isWeatherVisibleFlow = MutableStateFlow(false)
    private val isShadeLayoutWide = MutableStateFlow(false)


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


@@ -124,6 +127,26 @@ class SmartspaceSectionTest : SysuiTestCase() {
        assert(dateView.parent == null)
        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
    @Test
    fun testConstraintsWhenNotHasCustomWeatherDataDisplay() {
    fun testConstraintsWhenNotHasCustomWeatherDataDisplay() {
        whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
        whenever(keyguardSmartspaceViewModel.isDateWeatherDecoupled).thenReturn(true)
@@ -160,6 +183,7 @@ class SmartspaceSectionTest : SysuiTestCase() {
        assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(GONE)
        assertThat(constraintSet.getVisibility(weatherView.id)).isEqualTo(GONE)
        assertThat(constraintSet.getVisibility(dateView.id)).isEqualTo(VISIBLE)
        assertThat(constraintSet.getVisibility(dateView.id)).isEqualTo(VISIBLE)
    }
    }

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


            assertThat(isWeatherVisible).isEqualTo(false)
            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 Original line Diff line number Diff line
@@ -124,7 +124,7 @@ constructor(
                ConstraintSet.START,
                ConstraintSet.START,
                ConstraintSet.PARENT_ID,
                ConstraintSet.PARENT_ID,
                ConstraintSet.START,
                ConstraintSet.START,
                horizontalPaddingStart
                horizontalPaddingStart,
            )
            )


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


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


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


    val isShadeLayoutWide: StateFlow<Boolean> = shadeInteractor.isShadeLayoutWide

    companion object {
    companion object {
        fun getSmartspaceStartMargin(context: Context): Int {
        fun getSmartspaceStartMargin(context: Context): Int {
            return context.resources.getDimensionPixelSize(R.dimen.below_clock_padding_start) +
            return context.resources.getDimensionPixelSize(R.dimen.below_clock_padding_start) +
+2 −0
Original line number Original line 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.keyguard.domain.interactor.keyguardSmartspaceInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.mock


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