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

Commit 27f540e3 authored by Steve Elliott's avatar Steve Elliott Committed by Android (Google) Code Review
Browse files

Merge "MutableStateFlows in NotifKeyguardViewStateRepo" into main

parents 41658b47 32e13f64
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.notification.data.repository.fakeNotificationsKeyguardViewStateRepository
import com.android.systemui.statusbar.notification.stack.domain.interactor.notificationsKeyguardInteractor
import com.android.systemui.statusbar.phone.dozeParameters
import com.android.systemui.statusbar.phone.screenOffAnimationController
import com.android.systemui.testKosmos
@@ -56,8 +56,7 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
    private val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    private val screenOffAnimationController = kosmos.screenOffAnimationController
    private val deviceEntryRepository = kosmos.fakeDeviceEntryRepository
    private val fakeNotificationsKeyguardViewStateRepository =
        kosmos.fakeNotificationsKeyguardViewStateRepository
    private val notificationsKeyguardInteractor = kosmos.notificationsKeyguardInteractor
    private val dozeParameters = kosmos.dozeParameters
    private val underTest = kosmos.keyguardRootViewModel

@@ -118,7 +117,7 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(true)
            notificationsKeyguardInteractor.setPulseExpanding(true)
            deviceEntryRepository.setBypassEnabled(false)
            runCurrent()

@@ -130,9 +129,9 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(false)
            notificationsKeyguardInteractor.setPulseExpanding(false)
            deviceEntryRepository.setBypassEnabled(true)
            fakeNotificationsKeyguardViewStateRepository.setNotificationsFullyHidden(true)
            notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
            runCurrent()

            assertThat(isVisible?.value).isTrue()
@@ -144,10 +143,10 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(false)
            notificationsKeyguardInteractor.setPulseExpanding(false)
            deviceEntryRepository.setBypassEnabled(false)
            whenever(dozeParameters.alwaysOn).thenReturn(false)
            fakeNotificationsKeyguardViewStateRepository.setNotificationsFullyHidden(true)
            notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
            runCurrent()

            assertThat(isVisible?.value).isTrue()
@@ -159,11 +158,11 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(false)
            notificationsKeyguardInteractor.setPulseExpanding(false)
            deviceEntryRepository.setBypassEnabled(false)
            whenever(dozeParameters.alwaysOn).thenReturn(true)
            whenever(dozeParameters.displayNeedsBlanking).thenReturn(true)
            fakeNotificationsKeyguardViewStateRepository.setNotificationsFullyHidden(true)
            notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
            runCurrent()

            assertThat(isVisible?.value).isTrue()
@@ -175,11 +174,11 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(false)
            notificationsKeyguardInteractor.setPulseExpanding(false)
            deviceEntryRepository.setBypassEnabled(false)
            whenever(dozeParameters.alwaysOn).thenReturn(true)
            whenever(dozeParameters.displayNeedsBlanking).thenReturn(false)
            fakeNotificationsKeyguardViewStateRepository.setNotificationsFullyHidden(true)
            notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
            runCurrent()

            assertThat(isVisible?.value).isTrue()
@@ -191,11 +190,11 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
        testScope.runTest {
            val isVisible by collectLastValue(underTest.isNotifIconContainerVisible)
            runCurrent()
            fakeNotificationsKeyguardViewStateRepository.setPulseExpanding(false)
            notificationsKeyguardInteractor.setPulseExpanding(false)
            deviceEntryRepository.setBypassEnabled(false)
            whenever(dozeParameters.alwaysOn).thenReturn(true)
            whenever(dozeParameters.displayNeedsBlanking).thenReturn(false)
            fakeNotificationsKeyguardViewStateRepository.setNotificationsFullyHidden(true)
            notificationsKeyguardInteractor.setNotificationsFullyHidden(true)
            runCurrent()

            assertThat(isVisible?.isAnimating).isEqualTo(true)
+4 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.shade.ShadeExpansionListener
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.domain.interactor.NotificationsKeyguardInteractor
import com.android.systemui.statusbar.notification.shared.NotificationIconContainerRefactor
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController
import com.android.systemui.statusbar.notification.stack.StackStateAnimator
@@ -58,6 +59,7 @@ constructor(
    private val dozeParameters: DozeParameters,
    private val screenOffAnimationController: ScreenOffAnimationController,
    private val logger: NotificationWakeUpCoordinatorLogger,
    private val notifsKeyguardInteractor: NotificationsKeyguardInteractor,
) :
    OnHeadsUpChangedListener,
    StatusBarStateController.StateListener,
@@ -144,6 +146,7 @@ constructor(
                for (listener in wakeUpListeners) {
                    listener.onFullyHiddenChanged(value)
                }
                notifsKeyguardInteractor.setNotificationsFullyHidden(value)
            }
        }

@@ -216,6 +219,7 @@ constructor(
                for (listener in wakeUpListeners) {
                    listener.onPulseExpandingChanged(pulseExpanding)
                }
                notifsKeyguardInteractor.setPulseExpanding(pulseExpanding)
            }
        }
    }
+1 −3
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.systemui.statusbar.notification.data

import com.android.systemui.statusbar.notification.data.repository.NotificationsKeyguardStateRepositoryModule
import dagger.Module

@Module(includes = [NotificationsKeyguardStateRepositoryModule::class])
interface NotificationDataLayerModule
@Module(includes = []) interface NotificationDataLayerModule
+5 −48
Original line number Diff line number Diff line
@@ -15,59 +15,16 @@
 */
package com.android.systemui.statusbar.notification.data.repository

import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator
import dagger.Binds
import dagger.Module
import javax.inject.Inject
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow

/** View-states pertaining to notifications on the keyguard. */
interface NotificationsKeyguardViewStateRepository {
@SysUISingleton
class NotificationsKeyguardViewStateRepository @Inject constructor() {
    /** Are notifications fully hidden from view? */
    val areNotificationsFullyHidden: Flow<Boolean>
    val areNotificationsFullyHidden = MutableStateFlow(false)

    /** Is a pulse expansion occurring? */
    val isPulseExpanding: Flow<Boolean>
}

@Module
interface NotificationsKeyguardStateRepositoryModule {
    @Binds
    fun bindImpl(
        impl: NotificationsKeyguardViewStateRepositoryImpl
    ): NotificationsKeyguardViewStateRepository
}

@SysUISingleton
class NotificationsKeyguardViewStateRepositoryImpl
@Inject
constructor(
    wakeUpCoordinator: NotificationWakeUpCoordinator,
) : NotificationsKeyguardViewStateRepository {
    override val areNotificationsFullyHidden: Flow<Boolean> = conflatedCallbackFlow {
        val listener =
            object : NotificationWakeUpCoordinator.WakeUpListener {
                override fun onFullyHiddenChanged(isFullyHidden: Boolean) {
                    trySend(isFullyHidden)
                }
            }
        trySend(wakeUpCoordinator.notificationsFullyHidden)
        wakeUpCoordinator.addListener(listener)
        awaitClose { wakeUpCoordinator.removeListener(listener) }
    }

    override val isPulseExpanding: Flow<Boolean> = conflatedCallbackFlow {
        val listener =
            object : NotificationWakeUpCoordinator.WakeUpListener {
                override fun onPulseExpandingChanged(isPulseExpanding: Boolean) {
                    trySend(isPulseExpanding)
                }
            }
        trySend(wakeUpCoordinator.isPulseExpanding())
        wakeUpCoordinator.addListener(listener)
        awaitClose { wakeUpCoordinator.removeListener(listener) }
    }
    val isPulseExpanding = MutableStateFlow(false)
}
+13 −8
Original line number Diff line number Diff line
@@ -15,24 +15,29 @@
 */
package com.android.systemui.statusbar.notification.domain.interactor

import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.statusbar.notification.data.repository.NotificationsKeyguardViewStateRepository
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn

/** Domain logic pertaining to notifications on the keyguard. */
class NotificationsKeyguardInteractor
@Inject
constructor(
    repository: NotificationsKeyguardViewStateRepository,
    @Background backgroundDispatcher: CoroutineDispatcher,
    private val repository: NotificationsKeyguardViewStateRepository,
) {
    /** Is a pulse expansion occurring? */
    val isPulseExpanding: Flow<Boolean> = repository.isPulseExpanding.flowOn(backgroundDispatcher)
    val isPulseExpanding: Flow<Boolean> = repository.isPulseExpanding

    /** Are notifications fully hidden from view? */
    val areNotificationsFullyHidden: Flow<Boolean> =
        repository.areNotificationsFullyHidden.flowOn(backgroundDispatcher)
    val areNotificationsFullyHidden: Flow<Boolean> = repository.areNotificationsFullyHidden

    /** Updates whether notifications are fully hidden from view. */
    fun setNotificationsFullyHidden(fullyHidden: Boolean) {
        repository.areNotificationsFullyHidden.value = fullyHidden
    }

    /** Updates whether a pulse expansion is occurring. */
    fun setPulseExpanding(pulseExpanding: Boolean) {
        repository.isPulseExpanding.value = pulseExpanding
    }
}
Loading