Loading packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt +4 −5 Original line number Diff line number Diff line Loading @@ -21,16 +21,16 @@ import com.android.systemui.shared.settings.data.repository.SecureSettingsReposi import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext /** Provides access to state related to notification settings. */ class NotificationSettingsRepository( scope: CoroutineScope, private val scope: CoroutineScope, private val backgroundDispatcher: CoroutineDispatcher, private val secureSettingsRepository: SecureSettingsRepository, ) { Loading @@ -41,16 +41,15 @@ class NotificationSettingsRepository( .distinctUntilChanged() /** The current state of the notification setting. */ val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> = suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> = secureSettingsRepository .intSetting( name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, ) .map { it == 1 } .flowOn(backgroundDispatcher) .stateIn( scope = scope, started = SharingStarted.WhileSubscribed(), initialValue = false, ) suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) { Loading packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt +3 −3 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ class NotificationSettingsInteractor( val isNotificationHistoryEnabled = repository.isNotificationHistoryEnabled /** Should notifications be visible on the lockscreen? */ val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> = repository.isShowNotificationsOnLockScreenEnabled suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> = repository.isShowNotificationsOnLockScreenEnabled() suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) { repository.setShowNotificationsOnLockscreenEnabled(enabled) Loading @@ -35,7 +35,7 @@ class NotificationSettingsInteractor( /** Toggles the setting to show or hide notifications on the lock screen. */ suspend fun toggleShowNotificationsOnLockscreenEnabled() { val current = repository.isShowNotificationsOnLockScreenEnabled.value val current = repository.isShowNotificationsOnLockScreenEnabled().value repository.setShowNotificationsOnLockscreenEnabled(!current) } } packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class NotificationSettingsRepositoryTest : SysuiTestCase() { @Test fun testGetIsShowNotificationsOnLockscreenEnabled() = testScope.runTest { val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled) val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled()) secureSettingsRepository.setInt( name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, Loading @@ -74,7 +74,7 @@ class NotificationSettingsRepositoryTest : SysuiTestCase() { @Test fun testSetIsShowNotificationsOnLockscreenEnabled() = testScope.runTest { val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled) val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled()) underTest.setShowNotificationsOnLockscreenEnabled(true) assertThat(showNotifs).isEqualTo(true) Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt +4 −5 Original line number Diff line number Diff line Loading @@ -21,16 +21,16 @@ import com.android.systemui.shared.settings.data.repository.SecureSettingsReposi import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext /** Provides access to state related to notification settings. */ class NotificationSettingsRepository( scope: CoroutineScope, private val scope: CoroutineScope, private val backgroundDispatcher: CoroutineDispatcher, private val secureSettingsRepository: SecureSettingsRepository, ) { Loading @@ -41,16 +41,15 @@ class NotificationSettingsRepository( .distinctUntilChanged() /** The current state of the notification setting. */ val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> = suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> = secureSettingsRepository .intSetting( name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, ) .map { it == 1 } .flowOn(backgroundDispatcher) .stateIn( scope = scope, started = SharingStarted.WhileSubscribed(), initialValue = false, ) suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) { Loading
packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt +3 −3 Original line number Diff line number Diff line Loading @@ -26,8 +26,8 @@ class NotificationSettingsInteractor( val isNotificationHistoryEnabled = repository.isNotificationHistoryEnabled /** Should notifications be visible on the lockscreen? */ val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> = repository.isShowNotificationsOnLockScreenEnabled suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> = repository.isShowNotificationsOnLockScreenEnabled() suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) { repository.setShowNotificationsOnLockscreenEnabled(enabled) Loading @@ -35,7 +35,7 @@ class NotificationSettingsInteractor( /** Toggles the setting to show or hide notifications on the lock screen. */ suspend fun toggleShowNotificationsOnLockscreenEnabled() { val current = repository.isShowNotificationsOnLockScreenEnabled.value val current = repository.isShowNotificationsOnLockScreenEnabled().value repository.setShowNotificationsOnLockscreenEnabled(!current) } }
packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt +2 −2 Original line number Diff line number Diff line Loading @@ -56,7 +56,7 @@ class NotificationSettingsRepositoryTest : SysuiTestCase() { @Test fun testGetIsShowNotificationsOnLockscreenEnabled() = testScope.runTest { val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled) val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled()) secureSettingsRepository.setInt( name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, Loading @@ -74,7 +74,7 @@ class NotificationSettingsRepositoryTest : SysuiTestCase() { @Test fun testSetIsShowNotificationsOnLockscreenEnabled() = testScope.runTest { val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled) val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled()) underTest.setShowNotificationsOnLockscreenEnabled(true) assertThat(showNotifs).isEqualTo(true) Loading