Merge "Use ActiveNotificationsInteractor in NotificationVisibilityProviderImpl" into main
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/NotificationVisibilityProviderImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/NotificationVisibilityProviderImpl.kt
index ec10aaf..88e94e3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/NotificationVisibilityProviderImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/NotificationVisibilityProviderImpl.kt
@@ -22,12 +22,17 @@
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
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.shared.NotificationsLiveDataStoreRefactor
import javax.inject.Inject
/** pipeline-agnostic implementation for getting [NotificationVisibility]. */
@SysUISingleton
-class NotificationVisibilityProviderImpl @Inject constructor(
+class NotificationVisibilityProviderImpl
+@Inject
+constructor(
+ private val activeNotificationsInteractor: ActiveNotificationsInteractor,
private val notifDataStore: NotifLiveDataStore,
private val notifCollection: CommonNotifCollection
) : NotificationVisibilityProvider {
@@ -47,5 +52,10 @@
override fun getLocation(key: String): NotificationVisibility.NotificationLocation =
NotificationLogger.getNotificationLocation(notifCollection.getEntry(key))
- private fun getCount() = notifDataStore.activeNotifCount.value
+ private fun getCount() =
+ if (NotificationsLiveDataStoreRefactor.isEnabled) {
+ activeNotificationsInteractor.allNotificationsCountValue
+ } else {
+ notifDataStore.activeNotifCount.value
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractor.kt
index ca6344d..5180bab 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractor.kt
@@ -61,6 +61,15 @@
val allRepresentativeNotifications: Flow<Map<String, ActiveNotificationModel>> =
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? */
val areAnyNotificationsPresent: Flow<Boolean> =
repository.activeNotifications
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractorTest.kt
index b3b10eb..9b641f0 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/domain/interactor/ActiveNotificationsInteractorTest.kt
@@ -50,6 +50,18 @@
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
fun testAreAnyNotificationsPresent_isTrue() =
testComponent.runTest {
val areAnyNotificationsPresent by collectLastValue(underTest.areAnyNotificationsPresent)