summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Aaron Liu <aaronjli@google.com> 2024-03-25 13:50:12 -0700
committer Aaron Liu <aaronjli@google.com> 2024-03-27 10:08:24 -0700
commit38a8c65a1c6332a05d21e5c4b76e277f5f18da86 (patch)
tree96aeeef60b6a67835d7f20b688c95a46d4bb63a8
parent0f65a72e04603440d5f7c30495df94e0d0e15679 (diff)
Remove Notification from clock STL.
Removes the notification from the clock STL. Also remove some redundant composable invocations by adding additional reusable functions. Test: look at compose LS landscape and potrait with centering animation. Flag: ACONFIG com.android.systemui.compose_lockscreen DEVELOPMENT Bug: 301968149 Change-Id: I19aa4c5344cb3af4371098f94f0383bcd85d86a0
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/DefaultBlueprint.kt30
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/ShortcutsBesideUdfpsBlueprint.kt29
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/WeatherClockBlueprint.kt3
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/NotificationSection.kt34
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/TopAreaSection.kt206
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelTest.kt22
-rw-r--r--packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModel.kt27
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelKosmos.kt2
8 files changed, 188 insertions, 165 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/DefaultBlueprint.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/DefaultBlueprint.kt
index 320c455a8201..c008a1a4d192 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/DefaultBlueprint.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/DefaultBlueprint.kt
@@ -16,10 +16,15 @@
package com.android.systemui.keyguard.ui.composable.blueprint
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.IntRect
@@ -28,6 +33,7 @@ import com.android.systemui.keyguard.ui.composable.LockscreenLongPress
import com.android.systemui.keyguard.ui.composable.section.AmbientIndicationSection
import com.android.systemui.keyguard.ui.composable.section.BottomAreaSection
import com.android.systemui.keyguard.ui.composable.section.LockSection
+import com.android.systemui.keyguard.ui.composable.section.NotificationSection
import com.android.systemui.keyguard.ui.composable.section.SettingsMenuSection
import com.android.systemui.keyguard.ui.composable.section.StatusBarSection
import com.android.systemui.keyguard.ui.composable.section.TopAreaSection
@@ -52,6 +58,7 @@ constructor(
private val bottomAreaSection: BottomAreaSection,
private val settingsMenuSection: SettingsMenuSection,
private val topAreaSection: TopAreaSection,
+ private val notificationSection: NotificationSection,
) : ComposableLockscreenSceneBlueprint {
override val id: String = "default"
@@ -59,6 +66,8 @@ constructor(
@Composable
override fun SceneScope.Content(modifier: Modifier) {
val isUdfpsVisible = viewModel.isUdfpsVisible
+ val shouldUseSplitNotificationShade by
+ viewModel.shouldUseSplitNotificationShade.collectAsState()
LockscreenLongPress(
viewModel = viewModel.longPress,
@@ -68,10 +77,27 @@ constructor(
content = {
// Constrained to above the lock icon.
Column(
- modifier = Modifier.fillMaxWidth(),
+ modifier = Modifier.fillMaxSize(),
) {
with(statusBarSection) { StatusBar(modifier = Modifier.fillMaxWidth()) }
- with(topAreaSection) { DefaultClockLayoutWithNotifications() }
+
+ Box {
+ with(topAreaSection) { DefaultClockLayout() }
+ if (shouldUseSplitNotificationShade) {
+ with(notificationSection) {
+ Notifications(
+ Modifier.fillMaxWidth(0.5f)
+ .fillMaxHeight()
+ .align(alignment = Alignment.TopEnd)
+ )
+ }
+ }
+ }
+ if (!shouldUseSplitNotificationShade) {
+ with(notificationSection) {
+ Notifications(Modifier.weight(weight = 1f))
+ }
+ }
if (!isUdfpsVisible && ambientIndicationSectionOptional.isPresent) {
with(ambientIndicationSectionOptional.get()) {
AmbientIndication(modifier = Modifier.fillMaxWidth())
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/ShortcutsBesideUdfpsBlueprint.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/ShortcutsBesideUdfpsBlueprint.kt
index 64c2cb3670c8..091a43923a6e 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/ShortcutsBesideUdfpsBlueprint.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/ShortcutsBesideUdfpsBlueprint.kt
@@ -16,10 +16,15 @@
package com.android.systemui.keyguard.ui.composable.blueprint
+import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.unit.IntRect
@@ -28,6 +33,7 @@ import com.android.systemui.keyguard.ui.composable.LockscreenLongPress
import com.android.systemui.keyguard.ui.composable.section.AmbientIndicationSection
import com.android.systemui.keyguard.ui.composable.section.BottomAreaSection
import com.android.systemui.keyguard.ui.composable.section.LockSection
+import com.android.systemui.keyguard.ui.composable.section.NotificationSection
import com.android.systemui.keyguard.ui.composable.section.SettingsMenuSection
import com.android.systemui.keyguard.ui.composable.section.StatusBarSection
import com.android.systemui.keyguard.ui.composable.section.TopAreaSection
@@ -52,6 +58,7 @@ constructor(
private val bottomAreaSection: BottomAreaSection,
private val settingsMenuSection: SettingsMenuSection,
private val topAreaSection: TopAreaSection,
+ private val notificationSection: NotificationSection,
) : ComposableLockscreenSceneBlueprint {
override val id: String = "shortcuts-besides-udfps"
@@ -59,6 +66,8 @@ constructor(
@Composable
override fun SceneScope.Content(modifier: Modifier) {
val isUdfpsVisible = viewModel.isUdfpsVisible
+ val shouldUseSplitNotificationShade by
+ viewModel.shouldUseSplitNotificationShade.collectAsState()
LockscreenLongPress(
viewModel = viewModel.longPress,
@@ -68,11 +77,27 @@ constructor(
content = {
// Constrained to above the lock icon.
Column(
- modifier = Modifier.fillMaxWidth(),
+ modifier = Modifier.fillMaxSize(),
) {
with(statusBarSection) { StatusBar(modifier = Modifier.fillMaxWidth()) }
- with(topAreaSection) { DefaultClockLayoutWithNotifications() }
+ Box {
+ with(topAreaSection) { DefaultClockLayout() }
+ if (shouldUseSplitNotificationShade) {
+ with(notificationSection) {
+ Notifications(
+ Modifier.fillMaxWidth(0.5f)
+ .fillMaxHeight()
+ .align(alignment = Alignment.TopEnd)
+ )
+ }
+ }
+ }
+ if (!shouldUseSplitNotificationShade) {
+ with(notificationSection) {
+ Notifications(Modifier.weight(weight = 1f))
+ }
+ }
if (!isUdfpsVisible && ambientIndicationSectionOptional.isPresent) {
with(ambientIndicationSectionOptional.get()) {
AmbientIndication(modifier = Modifier.fillMaxWidth())
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/WeatherClockBlueprint.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/WeatherClockBlueprint.kt
index fe774a0d6db2..09d76a341442 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/WeatherClockBlueprint.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/blueprint/WeatherClockBlueprint.kt
@@ -86,6 +86,7 @@ constructor(
val burnIn = rememberBurnIn(clockInteractor)
val resources = LocalContext.current.resources
val currentClockState = clockViewModel.currentClock.collectAsState()
+ val areNotificationsVisible by viewModel.areNotificationsVisible.collectAsState()
LockscreenLongPress(
viewModel = viewModel.longPress,
modifier = modifier,
@@ -145,7 +146,7 @@ constructor(
with(mediaCarouselSection) { MediaCarousel() }
- if (viewModel.areNotificationsVisible) {
+ if (areNotificationsVisible) {
with(notificationSection) {
Notifications(
modifier = Modifier.fillMaxWidth().weight(weight = 1f)
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/NotificationSection.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/NotificationSection.kt
index 6b86a484069b..fa0a1c4663b1 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/NotificationSection.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/NotificationSection.kt
@@ -17,12 +17,25 @@
package com.android.systemui.keyguard.ui.composable.section
import android.view.ViewGroup
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.dimensionResource
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
import com.android.compose.animation.scene.SceneScope
+import com.android.compose.modifiers.thenIf
+import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.MigrateClocksToBlueprint
+import com.android.systemui.keyguard.ui.viewmodel.LockscreenContentViewModel
import com.android.systemui.notifications.ui.composable.NotificationStack
+import com.android.systemui.res.R
+import com.android.systemui.shade.LargeScreenHeaderHelper
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout
import com.android.systemui.statusbar.notification.stack.ui.view.SharedNotificationContainer
import com.android.systemui.statusbar.notification.stack.ui.viewbinder.SharedNotificationContainerBinder
@@ -39,6 +52,7 @@ constructor(
sharedNotificationContainerViewModel: SharedNotificationContainerViewModel,
stackScrollLayout: NotificationStackScrollLayout,
sharedNotificationContainerBinder: SharedNotificationContainerBinder,
+ private val lockscreenContentViewModel: LockscreenContentViewModel,
) {
init {
@@ -65,9 +79,27 @@ constructor(
@Composable
fun SceneScope.Notifications(modifier: Modifier = Modifier) {
+ val shouldUseSplitNotificationShade by
+ lockscreenContentViewModel.shouldUseSplitNotificationShade.collectAsState()
+ val areNotificationsVisible by
+ lockscreenContentViewModel.areNotificationsVisible.collectAsState()
+ val splitShadeTopMargin: Dp =
+ if (Flags.centralizedStatusBarHeightFix()) {
+ LargeScreenHeaderHelper.getLargeScreenHeaderHeight(LocalContext.current).dp
+ } else {
+ dimensionResource(id = R.dimen.large_screen_shade_header_height)
+ }
+
+ if (!areNotificationsVisible) {
+ return
+ }
+
NotificationStack(
viewModel = viewModel,
- modifier = modifier,
+ modifier =
+ modifier.fillMaxWidth().thenIf(shouldUseSplitNotificationShade) {
+ Modifier.padding(top = splitShadeTopMargin)
+ },
)
}
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/TopAreaSection.kt b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/TopAreaSection.kt
index b4472fc15ac4..f8e63411ed52 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/TopAreaSection.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/keyguard/ui/composable/section/TopAreaSection.kt
@@ -16,30 +16,20 @@
package com.android.systemui.keyguard.ui.composable.section
-import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.Row
-import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
-import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
-import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
-import androidx.compose.ui.platform.LocalContext
-import androidx.compose.ui.res.dimensionResource
-import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntOffset
-import androidx.compose.ui.unit.dp
+import com.android.compose.animation.scene.SceneScope
import com.android.compose.animation.scene.SceneTransitionLayout
import com.android.compose.modifiers.thenIf
-import com.android.systemui.Flags
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.ui.composable.blueprint.ClockScenes.largeClockScene
import com.android.systemui.keyguard.ui.composable.blueprint.ClockScenes.smallClockScene
@@ -48,8 +38,6 @@ import com.android.systemui.keyguard.ui.composable.blueprint.ClockScenes.splitSh
import com.android.systemui.keyguard.ui.composable.blueprint.ClockTransition
import com.android.systemui.keyguard.ui.composable.blueprint.rememberBurnIn
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
-import com.android.systemui.res.R
-import com.android.systemui.shade.LargeScreenHeaderHelper
import javax.inject.Inject
class TopAreaSection
@@ -58,19 +46,16 @@ constructor(
private val clockViewModel: KeyguardClockViewModel,
private val smartSpaceSection: SmartSpaceSection,
private val mediaCarouselSection: MediaCarouselSection,
- private val notificationSection: NotificationSection,
private val clockSection: DefaultClockSection,
private val clockInteractor: KeyguardClockInteractor,
) {
@Composable
- fun DefaultClockLayoutWithNotifications(
+ fun DefaultClockLayout(
modifier: Modifier = Modifier,
) {
- val isLargeClockVisible by clockViewModel.isLargeClockVisible.collectAsState()
val currentClockLayout by clockViewModel.currentClockLayout.collectAsState()
val hasCustomPositionUpdatedAnimation by
clockViewModel.hasCustomPositionUpdatedAnimation.collectAsState()
-
val currentScene =
when (currentClockLayout) {
KeyguardClockViewModel.ClockLayout.SPLIT_SHADE_LARGE_CLOCK ->
@@ -81,144 +66,83 @@ constructor(
KeyguardClockViewModel.ClockLayout.SMALL_CLOCK -> smallClockScene
}
- val splitShadeTopMargin: Dp =
- if (Flags.centralizedStatusBarHeightFix()) {
- LargeScreenHeaderHelper.getLargeScreenHeaderHeight(LocalContext.current).dp
- } else {
- dimensionResource(id = R.dimen.large_screen_shade_header_height)
- }
- val burnIn = rememberBurnIn(clockInteractor)
-
- LaunchedEffect(isLargeClockVisible) {
- if (isLargeClockVisible) {
- burnIn.onSmallClockTopChanged(null)
- }
- }
-
SceneTransitionLayout(
- modifier = modifier.fillMaxSize(),
+ modifier = modifier,
currentScene = currentScene,
onChangeScene = {},
transitions = ClockTransition.defaultClockTransitions,
enableInterruptions = false,
) {
scene(splitShadeLargeClockScene) {
- Box(modifier = Modifier.fillMaxSize()) {
- Column(
- modifier = Modifier.fillMaxSize(),
- horizontalAlignment = Alignment.CenterHorizontally,
- ) {
- with(smartSpaceSection) {
- SmartSpace(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmartspaceTopChanged,
- )
- }
-
- with(clockSection) {
- LargeClock(
- modifier =
- Modifier.fillMaxSize().thenIf(
- !hasCustomPositionUpdatedAnimation
- ) {
- // If we do not have a custom position animation, we want
- // the clock to be on one half of the screen.
- Modifier.offset {
- IntOffset(
- x =
- -clockSection
- .getClockCenteringDistance()
- .toInt(),
- y = 0,
- )
- }
- }
- )
- }
- }
- }
-
- Row(
- modifier = Modifier.fillMaxSize(),
- ) {
- Spacer(modifier = Modifier.weight(weight = 1f))
- with(notificationSection) {
- Notifications(
- modifier =
- Modifier.fillMaxHeight()
- .weight(weight = 1f)
- .padding(top = splitShadeTopMargin)
- )
- }
- }
+ LargeClockWithSmartSpace(
+ shouldOffSetClockToOneHalf = !hasCustomPositionUpdatedAnimation
+ )
}
scene(splitShadeSmallClockScene) {
- Row(
- modifier = Modifier.fillMaxSize(),
- ) {
- Column(
- modifier = Modifier.fillMaxHeight().weight(weight = 1f),
- horizontalAlignment = Alignment.CenterHorizontally,
- ) {
- with(clockSection) {
- SmallClock(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmallClockTopChanged,
- modifier = Modifier.wrapContentSize()
- )
- }
- with(smartSpaceSection) {
- SmartSpace(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmartspaceTopChanged,
- )
- }
- with(mediaCarouselSection) { MediaCarousel() }
- }
- with(notificationSection) {
- Notifications(
- modifier =
- Modifier.fillMaxHeight()
- .weight(weight = 1f)
- .padding(top = splitShadeTopMargin)
- )
- }
- }
+ SmallClockWithSmartSpace(modifier = Modifier.fillMaxWidth(0.5f))
}
- scene(smallClockScene) {
- Column {
- with(clockSection) {
- SmallClock(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmallClockTopChanged,
- modifier = Modifier.wrapContentSize()
- )
- }
- with(smartSpaceSection) {
- SmartSpace(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmartspaceTopChanged,
- )
- }
- with(mediaCarouselSection) { MediaCarousel() }
- with(notificationSection) {
- Notifications(modifier = Modifier.fillMaxWidth().weight(weight = 1f))
- }
- }
+ scene(smallClockScene) { SmallClockWithSmartSpace() }
+
+ scene(largeClockScene) { LargeClockWithSmartSpace() }
+ }
+ }
+
+ @Composable
+ private fun SceneScope.SmallClockWithSmartSpace(modifier: Modifier = Modifier) {
+ val burnIn = rememberBurnIn(clockInteractor)
+
+ Column(modifier = modifier) {
+ with(clockSection) {
+ SmallClock(
+ burnInParams = burnIn.parameters,
+ onTopChanged = burnIn.onSmallClockTopChanged,
+ modifier = Modifier.wrapContentSize()
+ )
+ }
+ with(smartSpaceSection) {
+ SmartSpace(
+ burnInParams = burnIn.parameters,
+ onTopChanged = burnIn.onSmartspaceTopChanged,
+ )
}
+ with(mediaCarouselSection) { MediaCarousel() }
+ }
+ }
- scene(largeClockScene) {
- Column {
- with(smartSpaceSection) {
- SmartSpace(
- burnInParams = burnIn.parameters,
- onTopChanged = burnIn.onSmartspaceTopChanged,
- )
- }
- with(clockSection) { LargeClock(modifier = Modifier.fillMaxSize()) }
- }
+ @Composable
+ private fun SceneScope.LargeClockWithSmartSpace(shouldOffSetClockToOneHalf: Boolean = false) {
+ val burnIn = rememberBurnIn(clockInteractor)
+ val isLargeClockVisible by clockViewModel.isLargeClockVisible.collectAsState()
+
+ LaunchedEffect(isLargeClockVisible) {
+ if (isLargeClockVisible) {
+ burnIn.onSmallClockTopChanged(null)
+ }
+ }
+
+ Column {
+ with(smartSpaceSection) {
+ SmartSpace(
+ burnInParams = burnIn.parameters,
+ onTopChanged = burnIn.onSmartspaceTopChanged,
+ )
+ }
+ with(clockSection) {
+ LargeClock(
+ modifier =
+ Modifier.fillMaxSize().thenIf(shouldOffSetClockToOneHalf) {
+ // If we do not have a custom position animation, we want
+ // the clock to be on one half of the screen.
+ Modifier.offset {
+ IntOffset(
+ x = -clockSection.getClockCenteringDistance().toInt(),
+ y = 0,
+ )
+ }
+ }
+ )
}
}
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelTest.kt
index 751ac1d8b458..e9a825721f5f 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelTest.kt
@@ -21,6 +21,7 @@ import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardClockSwitch
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.authController
+import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardClockRepository
@@ -96,7 +97,7 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
shadeRepository.setShadeMode(ShadeMode.Split)
kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.LARGE)
- assertThat(underTest.areNotificationsVisible).isTrue()
+ assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isTrue()
}
}
@Test
@@ -104,7 +105,7 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
with(kosmos) {
testScope.runTest {
kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.SMALL)
- assertThat(underTest.areNotificationsVisible).isTrue()
+ assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isTrue()
}
}
@@ -113,7 +114,7 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
with(kosmos) {
testScope.runTest {
kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.LARGE)
- assertThat(underTest.areNotificationsVisible).isFalse()
+ assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isFalse()
}
}
@@ -122,7 +123,8 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
with(kosmos) {
testScope.runTest {
shadeRepository.setShadeMode(ShadeMode.Split)
- assertThat(underTest.shouldUseSplitNotificationShade).isTrue()
+ assertThat(collectLastValue(underTest.shouldUseSplitNotificationShade).invoke())
+ .isTrue()
}
}
@@ -131,16 +133,8 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
with(kosmos) {
testScope.runTest {
shadeRepository.setShadeMode(ShadeMode.Single)
- assertThat(underTest.shouldUseSplitNotificationShade).isFalse()
- }
- }
-
- @Test
- fun sceneKey() =
- with(kosmos) {
- testScope.runTest {
- shadeRepository.setShadeMode(ShadeMode.Single)
- assertThat(underTest.shouldUseSplitNotificationShade).isFalse()
+ assertThat(collectLastValue(underTest.shouldUseSplitNotificationShade).invoke())
+ .isFalse()
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModel.kt
index 1f80441492bc..36896f916e7d 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModel.kt
@@ -18,8 +18,10 @@ package com.android.systemui.keyguard.ui.viewmodel
import android.content.res.Resources
import com.android.keyguard.KeyguardClockSwitch
+import com.android.keyguard.KeyguardClockSwitch.SMALL
import com.android.systemui.biometrics.AuthController
import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.res.R
@@ -29,6 +31,7 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
@@ -42,6 +45,7 @@ constructor(
private val authController: AuthController,
val longPress: KeyguardLongPressViewModel,
val shadeInteractor: ShadeInteractor,
+ @Application private val applicationScope: CoroutineScope,
) {
private val clockSize = clockInteractor.clockSize
@@ -50,11 +54,26 @@ constructor(
val isLargeClockVisible: Boolean
get() = clockSize.value == KeyguardClockSwitch.LARGE
- val areNotificationsVisible: Boolean
- get() = !isLargeClockVisible || shouldUseSplitNotificationShade
+ val shouldUseSplitNotificationShade: StateFlow<Boolean> =
+ shadeInteractor.shadeMode
+ .map { it == ShadeMode.Split }
+ .stateIn(
+ scope = applicationScope,
+ started = SharingStarted.WhileSubscribed(),
+ initialValue = false,
+ )
- val shouldUseSplitNotificationShade: Boolean
- get() = shadeInteractor.shadeMode.value == ShadeMode.Split
+ val areNotificationsVisible: StateFlow<Boolean> =
+ combine(clockSize, shouldUseSplitNotificationShade) {
+ clockSize,
+ shouldUseSplitNotificationShade ->
+ clockSize == SMALL || shouldUseSplitNotificationShade
+ }
+ .stateIn(
+ scope = applicationScope,
+ started = SharingStarted.WhileSubscribed(),
+ initialValue = false,
+ )
fun getSmartSpacePaddingTop(resources: Resources): Int {
return if (isLargeClockVisible) {
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelKosmos.kt
index f0fedd2ed479..1e25f7fd470e 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenContentViewModelKosmos.kt
@@ -20,6 +20,7 @@ import com.android.systemui.biometrics.authController
import com.android.systemui.keyguard.domain.interactor.keyguardBlueprintInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardClockInteractor
import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.shade.domain.interactor.shadeInteractor
val Kosmos.lockscreenContentViewModel by
@@ -30,5 +31,6 @@ val Kosmos.lockscreenContentViewModel by
authController = authController,
longPress = keyguardLongPressViewModel,
shadeInteractor = shadeInteractor,
+ applicationScope = applicationCoroutineScope,
)
}