• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 package com.android.customization.picker.notifications.domain.interactor
19 
20 import com.android.customization.picker.notifications.data.repository.NotificationsRepository
21 import com.android.customization.picker.notifications.shared.model.NotificationSettingsModel
22 import javax.inject.Provider
23 import kotlinx.coroutines.flow.Flow
24 
25 /** Encapsulates business logic for interacting with notifications. */
26 class NotificationsInteractor(
27     private val repository: NotificationsRepository,
28     private val snapshotRestorer: Provider<NotificationsSnapshotRestorer>,
29 ) {
30     /** The current state of the notification setting. */
31     val settings: Flow<NotificationSettingsModel> = repository.settings
32 
33     /** Toggles the setting to show or hide notifications on the lock screen. */
toggleShowNotificationsOnLockScreenEnablednull34     suspend fun toggleShowNotificationsOnLockScreenEnabled() {
35         val currentModel = repository.getSettings()
36         setSettings(
37             currentModel.copy(
38                 isShowNotificationsOnLockScreenEnabled =
39                     !currentModel.isShowNotificationsOnLockScreenEnabled,
40             )
41         )
42     }
43 
setSettingsnull44     suspend fun setSettings(model: NotificationSettingsModel) {
45         repository.setSettings(model)
46         snapshotRestorer.get().storeSnapshot(model)
47     }
48 
getSettingsnull49     suspend fun getSettings(): NotificationSettingsModel {
50         return repository.getSettings()
51     }
52 }
53