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

Commit 47c9bae0 authored by burakov's avatar burakov
Browse files

[Dual Shade] Show the notifications shade clock when the shade is empty.

Bug: 404798547
Test: Existing unit tests still pass.
Test: Manually by opening the notifications shade with and without
 notifications present, and observing that the clock is shown in both
 cases (and not shown in both cases when the device is unfolded).
Flag: com.android.systemui.scene_container
Change-Id: Ifa9272a755aef128c17d1366f0ffb9fa6d18b479
parent 7c3a2d8c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.ui.composable.Overlay
import com.android.systemui.shade.ui.composable.OverlayShade
import com.android.systemui.shade.ui.composable.OverlayShadeHeader
import com.android.systemui.shade.ui.composable.isFullWidthShade
import com.android.systemui.statusbar.notification.stack.ui.view.NotificationScrollView
import com.android.systemui.util.Utils
import dagger.Lazy
@@ -117,7 +118,7 @@ constructor(
        ) {
            Box {
                Column {
                    if (viewModel.showClock) {
                    if (isFullWidthShade()) {
                        val burnIn = rememberBurnIn(keyguardClockViewModel)

                        with(clockSection) {
+0 −35
Original line number Diff line number Diff line
@@ -38,13 +38,10 @@ import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.domain.startable.sceneContainerStartable
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.data.repository.shadeRepository
import com.android.systemui.shade.domain.interactor.enableDualShade
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.ui.viewmodel.notificationsShadeOverlayContentViewModel
import com.android.systemui.statusbar.disableflags.data.repository.fakeDisableFlagsRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.data.repository.setActiveNotifs
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -115,38 +112,6 @@ class NotificationsShadeOverlayContentViewModelTest : SysuiTestCase() {
            assertThat(currentOverlays).doesNotContain(Overlays.NotificationsShade)
        }

    @Test
    fun showClock_showsOnNarrowScreen() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(false)

            // Shown when notifications are present.
            kosmos.activeNotificationListRepository.setActiveNotifs(1)
            runCurrent()
            assertThat(underTest.showClock).isTrue()

            // Hidden when notifications are not present.
            kosmos.activeNotificationListRepository.setActiveNotifs(0)
            runCurrent()
            assertThat(underTest.showClock).isFalse()
        }

    @Test
    fun showClock_hidesOnWideScreen() =
        testScope.runTest {
            kosmos.shadeRepository.setShadeLayoutWide(true)

            // Hidden when notifications are present.
            kosmos.activeNotificationListRepository.setActiveNotifs(1)
            runCurrent()
            assertThat(underTest.showClock).isFalse()

            // Hidden when notifications are not present.
            kosmos.activeNotificationListRepository.setActiveNotifs(0)
            runCurrent()
            assertThat(underTest.showClock).isFalse()
        }

    @Test
    fun showMedia_activeMedia_true() =
        testScope.runTest {
+0 −29
Original line number Diff line number Diff line
@@ -23,17 +23,14 @@ import com.android.systemui.lifecycle.Hydrator
import com.android.systemui.media.controls.domain.pipeline.interactor.MediaCarouselInteractor
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
import com.android.systemui.shade.ui.viewmodel.ShadeHeaderViewModel
import com.android.systemui.statusbar.disableflags.domain.interactor.DisableFlagsInteractor
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationsPlaceholderViewModel
import com.android.systemui.utils.coroutines.flow.flatMapLatestConflated
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.flowOf
@@ -51,31 +48,12 @@ constructor(
    val notificationsPlaceholderViewModelFactory: NotificationsPlaceholderViewModel.Factory,
    val sceneInteractor: SceneInteractor,
    private val shadeInteractor: ShadeInteractor,
    shadeModeInteractor: ShadeModeInteractor,
    disableFlagsInteractor: DisableFlagsInteractor,
    mediaCarouselInteractor: MediaCarouselInteractor,
    activeNotificationsInteractor: ActiveNotificationsInteractor,
) : ExclusiveActivatable() {

    private val hydrator = Hydrator("NotificationsShadeOverlayContentViewModel.hydrator")

    val showClock: Boolean by
        hydrator.hydratedStateOf(
            traceName = "showClock",
            initialValue =
                shouldShowClock(
                    isShadeLayoutWide = shadeModeInteractor.isShadeLayoutWide.value,
                    areAnyNotificationsPresent =
                        activeNotificationsInteractor.areAnyNotificationsPresentValue,
                ),
            source =
                combine(
                    shadeModeInteractor.isShadeLayoutWide,
                    activeNotificationsInteractor.areAnyNotificationsPresent,
                    this::shouldShowClock,
                ),
        )

    val showMedia: Boolean by
        hydrator.hydratedStateOf(
            traceName = "showMedia",
@@ -114,13 +92,6 @@ constructor(
        shadeInteractor.collapseNotificationsShade(loggingReason = "shade scrim clicked")
    }

    private fun shouldShowClock(
        isShadeLayoutWide: Boolean,
        areAnyNotificationsPresent: Boolean,
    ): Boolean {
        return !isShadeLayoutWide && areAnyNotificationsPresent
    }

    @AssistedFactory
    interface Factory {
        fun create(): NotificationsShadeOverlayContentViewModel
+0 −4
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ import com.android.systemui.media.controls.domain.pipeline.interactor.mediaCarou
import com.android.systemui.notifications.ui.viewmodel.NotificationsShadeOverlayContentViewModel
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.domain.interactor.shadeModeInteractor
import com.android.systemui.statusbar.disableflags.domain.interactor.disableFlagsInteractor
import com.android.systemui.statusbar.notification.domain.interactor.activeNotificationsInteractor
import com.android.systemui.statusbar.notification.stack.ui.viewmodel.notificationsPlaceholderViewModelFactory

val Kosmos.notificationsShadeOverlayContentViewModel:
@@ -34,9 +32,7 @@ val Kosmos.notificationsShadeOverlayContentViewModel:
        notificationsPlaceholderViewModelFactory = notificationsPlaceholderViewModelFactory,
        sceneInteractor = sceneInteractor,
        shadeInteractor = shadeInteractor,
        shadeModeInteractor = shadeModeInteractor,
        disableFlagsInteractor = disableFlagsInteractor,
        mediaCarouselInteractor = mediaCarouselInteractor,
        activeNotificationsInteractor = activeNotificationsInteractor,
    )
}