Update usages of NotificationSettingsInteractor
Changed the interactor & repository to hold individual settings rather
than one object with all of them. This CL updates the usages, and also
moves the NotificationSettingsRepositoryTest to frameworks/base (see
other CL in topic).
Bug: 293167744
Test: NotificationSettingsRepositoryTest + verified manually that the
lockscreen notif toggle works correctly
Flag: NONE
Change-Id: I108867263f976fa550e08bc9718fac71074a73ce
diff --git a/src/com/android/customization/picker/notifications/domain/interactor/NotificationsSnapshotRestorer.kt b/src/com/android/customization/picker/notifications/domain/interactor/NotificationsSnapshotRestorer.kt
index 9dc8872..09d2d29 100644
--- a/src/com/android/customization/picker/notifications/domain/interactor/NotificationsSnapshotRestorer.kt
+++ b/src/com/android/customization/picker/notifications/domain/interactor/NotificationsSnapshotRestorer.kt
@@ -17,7 +17,6 @@
package com.android.customization.picker.notifications.domain.interactor
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
-import com.android.systemui.shared.notifications.shared.model.NotificationSettingsModel
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotStore
@@ -33,7 +32,7 @@
private var snapshotStore: SnapshotStore = SnapshotStore.NOOP
- private fun storeSnapshot(model: NotificationSettingsModel) {
+ private fun storeSnapshot(model: NotificationSnapshotModel) {
snapshotStore.store(snapshot(model))
}
@@ -41,21 +40,25 @@
store: SnapshotStore,
): RestorableSnapshot {
snapshotStore = store
- backgroundScope.launch { interactor.settings.collect { model -> storeSnapshot(model) } }
- return snapshot(interactor.getSettings())
+ backgroundScope.launch {
+ interactor.isShowNotificationsOnLockScreenEnabled.collect {
+ storeSnapshot(
+ NotificationSnapshotModel(isShowNotificationsOnLockScreenEnabled = it)
+ )
+ }
+ }
+ return snapshot(
+ NotificationSnapshotModel(interactor.isShowNotificationsOnLockScreenEnabled.value)
+ )
}
override suspend fun restoreToSnapshot(snapshot: RestorableSnapshot) {
val isShowNotificationsOnLockScreenEnabled =
snapshot.args[KEY_IS_SHOW_NOTIFICATIONS_ON_LOCK_SCREEN_ENABLED]?.toBoolean() ?: false
- interactor.setSettings(
- NotificationSettingsModel(
- isShowNotificationsOnLockScreenEnabled = isShowNotificationsOnLockScreenEnabled,
- )
- )
+ interactor.setShowNotificationsOnLockscreenEnabled(isShowNotificationsOnLockScreenEnabled)
}
- private fun snapshot(model: NotificationSettingsModel): RestorableSnapshot {
+ private fun snapshot(model: NotificationSnapshotModel): RestorableSnapshot {
return RestorableSnapshot(
mapOf(
KEY_IS_SHOW_NOTIFICATIONS_ON_LOCK_SCREEN_ENABLED to
@@ -69,3 +72,9 @@
"is_show_notifications_on_lock_screen_enabled"
}
}
+
+/** Snapshot of notification settings relevant to the theme picker. */
+private data class NotificationSnapshotModel(
+ /** Whether notifications are shown on the lock screen. */
+ val isShowNotificationsOnLockScreenEnabled: Boolean = false,
+)
diff --git a/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModel.kt b/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModel.kt
index 86a2693..5db7626 100644
--- a/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModel.kt
+++ b/src/com/android/customization/picker/notifications/ui/viewmodel/NotificationSectionViewModel.kt
@@ -24,7 +24,6 @@
import com.android.customization.module.logging.ThemesUserEventLogger
import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
/** Models UI state for a section that lets the user control the notification settings. */
@@ -36,15 +35,14 @@
) : ViewModel() {
/** Whether the switch should be on. */
- val isSwitchOn: Flow<Boolean> =
- interactor.settings.map { model -> model.isShowNotificationsOnLockScreenEnabled }
+ val isSwitchOn: Flow<Boolean> = interactor.isShowNotificationsOnLockScreenEnabled
/** Notifies that the section has been clicked. */
fun onClicked() {
viewModelScope.launch {
- interactor.toggleShowNotificationsOnLockScreenEnabled()
+ interactor.toggleShowNotificationsOnLockscreenEnabled()
logger.logLockScreenNotificationApplied(
- interactor.getSettings().isShowNotificationsOnLockScreenEnabled
+ interactor.isShowNotificationsOnLockScreenEnabled.value
)
}
}
diff --git a/tests/robotests/src/com/android/customization/picker/repository/NotificationSettingsRepositoryTest.kt b/tests/robotests/src/com/android/customization/picker/repository/NotificationSettingsRepositoryTest.kt
deleted file mode 100644
index bb6f292..0000000
--- a/tests/robotests/src/com/android/customization/picker/repository/NotificationSettingsRepositoryTest.kt
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.customization.picker.repository
-
-import android.provider.Settings
-import androidx.test.filters.SmallTest
-import com.android.systemui.shared.notifications.data.repository.NotificationSettingsRepository
-import com.android.systemui.shared.notifications.shared.model.NotificationSettingsModel
-import com.android.systemui.shared.settings.data.repository.FakeSecureSettingsRepository
-import com.android.wallpaper.testing.collectLastValue
-import com.google.common.truth.Truth.assertThat
-import kotlinx.coroutines.test.StandardTestDispatcher
-import kotlinx.coroutines.test.TestScope
-import kotlinx.coroutines.test.runTest
-import org.junit.Before
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-
-@SmallTest
-@RunWith(JUnit4::class)
-class NotificationSettingsRepositoryTest {
-
- private lateinit var underTest: NotificationSettingsRepository
-
- private lateinit var testScope: TestScope
- private lateinit var secureSettingsRepository: FakeSecureSettingsRepository
-
- @Before
- fun setUp() {
- val testDispatcher = StandardTestDispatcher()
- testScope = TestScope(testDispatcher)
- secureSettingsRepository = FakeSecureSettingsRepository()
-
- underTest =
- NotificationSettingsRepository(
- scope = testScope.backgroundScope,
- backgroundDispatcher = testDispatcher,
- secureSettingsRepository = secureSettingsRepository,
- )
- }
-
- @Test
- fun settings() =
- testScope.runTest {
- val settings = collectLastValue(underTest.settings)
-
- secureSettingsRepository.set(
- name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
- value = 1,
- )
- assertThat(settings())
- .isEqualTo(NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = true))
-
- secureSettingsRepository.set(
- name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
- value = 0,
- )
- assertThat(settings())
- .isEqualTo(
- NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = false)
- )
- }
-
- @Test
- fun setSettings() =
- testScope.runTest {
- val settings = collectLastValue(underTest.settings)
-
- val model1 = NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = true)
- underTest.setSettings(model1)
- assertThat(settings()).isEqualTo(model1)
-
- val model2 = NotificationSettingsModel(isShowNotificationsOnLockScreenEnabled = false)
- underTest.setSettings(model2)
- assertThat(settings()).isEqualTo(model2)
- }
-}