1 /*
<lambda>null2  * 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 package com.android.systemui.statusbar.policy.domain.interactor
18 
19 import android.provider.Settings
20 import com.android.systemui.statusbar.policy.data.repository.ZenModeRepository
21 import javax.inject.Inject
22 import kotlinx.coroutines.flow.Flow
23 import kotlinx.coroutines.flow.combine
24 import kotlinx.coroutines.flow.distinctUntilChanged
25 import kotlinx.coroutines.flow.map
26 
27 /**
28  * An interactor that performs business logic related to the status and configuration of Zen Mode
29  * (or Do Not Disturb/DND Mode).
30  */
31 class ZenModeInteractor @Inject constructor(repository: ZenModeRepository) {
32     val isZenModeEnabled: Flow<Boolean> =
33         repository.zenMode
34             .map {
35                 when (it) {
36                     Settings.Global.ZEN_MODE_ALARMS -> true
37                     Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS -> true
38                     Settings.Global.ZEN_MODE_NO_INTERRUPTIONS -> true
39                     Settings.Global.ZEN_MODE_OFF -> false
40                     else -> false
41                 }
42             }
43             .distinctUntilChanged()
44 
45     val areNotificationsHiddenInShade: Flow<Boolean> =
46         combine(isZenModeEnabled, repository.consolidatedNotificationPolicy) { dndEnabled, policy ->
47                 if (!dndEnabled) {
48                     false
49                 } else {
50                     val showInNotificationList = policy?.showInNotificationList() ?: true
51                     !showInNotificationList
52                 }
53             }
54             .distinctUntilChanged()
55 }
56