diff options
| author | 2024-01-11 17:17:20 +0000 | |
|---|---|---|
| committer | 2024-01-15 11:26:21 +0000 | |
| commit | 14eabcd68359aaa6db9d17a038f797d9a31699c8 (patch) | |
| tree | b9d9d15c8ee24857c9e31291ab4b237a0839de08 | |
| parent | c219f435b4ed0cbdb36e5bd55acac78fefc856b3 (diff) | |
Use ActiveNotificationsInteractor in NotificationVisibilityProviderImpl
Bug: 308623704
Test: atest ActiveNotificationsInteractorTest
Flag: ACONFIG com.android.systemui.notifications_live_data_store_refactor DEVELOPMENT
Change-Id: I3ef143b59d7f70ddb13c8127319fa31208a7dfd4
3 files changed, 33 insertions, 2 deletions
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 ec10aaf3cfe3..88e94e354913 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.NotifLiveDataStore 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 @@ class NotificationVisibilityProviderImpl @Inject constructor( 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 ca6344d07df8..5180bab60fdf 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 @@ constructor( 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 b3b10eb8aec3..9b641f014c01 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 @@ class ActiveNotificationsInteractorTest : SysuiTestCase() { 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) |