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

Commit fcf5c037 authored by Catherine Liang's avatar Catherine Liang Committed by Android (Google) Code Review
Browse files

Merge "Fix notifications undo system (2/2)" into main

parents e4e5b0bd b25cf3dd
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -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,
) {
@@ -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) {
+3 −3
Original line number Diff line number Diff line
@@ -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)
@@ -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)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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,
@@ -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)