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

Commit 511030f6 authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "Use ActiveNotificationsInteractor in NotificationVisibilityProviderImpl" into main

parents 36bfc0d7 14eabcd6
Loading
Loading
Loading
Loading
+12 −2
Original line number Original line Diff line number Diff line
@@ -22,12 +22,17 @@ import com.android.systemui.statusbar.notification.collection.NotifLiveDataStore
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider
import com.android.systemui.statusbar.notification.domain.interactor.ActiveNotificationsInteractor
import com.android.systemui.statusbar.notification.logging.NotificationLogger
import com.android.systemui.statusbar.notification.logging.NotificationLogger
import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor
import javax.inject.Inject
import javax.inject.Inject


/** pipeline-agnostic implementation for getting [NotificationVisibility]. */
/** pipeline-agnostic implementation for getting [NotificationVisibility]. */
@SysUISingleton
@SysUISingleton
class NotificationVisibilityProviderImpl @Inject constructor(
class NotificationVisibilityProviderImpl
@Inject
constructor(
    private val activeNotificationsInteractor: ActiveNotificationsInteractor,
    private val notifDataStore: NotifLiveDataStore,
    private val notifDataStore: NotifLiveDataStore,
    private val notifCollection: CommonNotifCollection
    private val notifCollection: CommonNotifCollection
) : NotificationVisibilityProvider {
) : NotificationVisibilityProvider {
@@ -47,5 +52,10 @@ class NotificationVisibilityProviderImpl @Inject constructor(
    override fun getLocation(key: String): NotificationVisibility.NotificationLocation =
    override fun getLocation(key: String): NotificationVisibility.NotificationLocation =
        NotificationLogger.getNotificationLocation(notifCollection.getEntry(key))
        NotificationLogger.getNotificationLocation(notifCollection.getEntry(key))


    private fun getCount() = notifDataStore.activeNotifCount.value
    private fun getCount() =
        if (NotificationsLiveDataStoreRefactor.isEnabled) {
            activeNotificationsInteractor.allNotificationsCountValue
        } else {
            notifDataStore.activeNotifCount.value
        }
}
}
+9 −0
Original line number Original line Diff line number Diff line
@@ -61,6 +61,15 @@ constructor(
    val allRepresentativeNotifications: Flow<Map<String, ActiveNotificationModel>> =
    val allRepresentativeNotifications: Flow<Map<String, ActiveNotificationModel>> =
        repository.activeNotifications.map { store -> store.individuals }
        repository.activeNotifications.map { store -> store.individuals }


    /** Size of the flattened list of Notifications actively presented in the stack. */
    val allNotificationsCount: Flow<Int> =
        repository.activeNotifications.map { store -> store.individuals.size }

    /**
     * The same as [allNotificationsCount], but without flows, for easy access in synchronous code.
     */
    val allNotificationsCountValue: Int = repository.activeNotifications.value.individuals.size

    /** Are any notifications being actively presented in the notification stack? */
    /** Are any notifications being actively presented in the notification stack? */
    val areAnyNotificationsPresent: Flow<Boolean> =
    val areAnyNotificationsPresent: Flow<Boolean> =
        repository.activeNotifications
        repository.activeNotifications
+12 −0
Original line number Original line Diff line number Diff line
@@ -49,6 +49,18 @@ class ActiveNotificationsInteractorTest : SysuiTestCase() {
    private val testComponent: TestComponent =
    private val testComponent: TestComponent =
        DaggerActiveNotificationsInteractorTest_TestComponent.factory().create(test = this)
        DaggerActiveNotificationsInteractorTest_TestComponent.factory().create(test = this)


    @Test
    fun testAllNotificationsCount() =
        testComponent.runTest {
            val count by collectLastValue(underTest.allNotificationsCount)

            activeNotificationListRepository.setActiveNotifs(5)
            runCurrent()

            assertThat(count).isEqualTo(5)
            assertThat(underTest.allNotificationsCountValue).isEqualTo(5)
        }

    @Test
    @Test
    fun testAreAnyNotificationsPresent_isTrue() =
    fun testAreAnyNotificationsPresent_isTrue() =
        testComponent.runTest {
        testComponent.runTest {