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 package com.android.systemui.statusbar.notification.domain.interactor
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.statusbar.notification.collection.NotificationEntry
21 import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationListRepository
22 import com.android.systemui.statusbar.notification.shared.NotificationMinimalismPrototype
23 import javax.inject.Inject
24 import kotlinx.coroutines.flow.StateFlow
25 
26 /** Interactor for business logic associated with the notification stack. */
27 @SysUISingleton
28 class SeenNotificationsInteractor
29 @Inject
30 constructor(
31     private val notificationListRepository: ActiveNotificationListRepository,
32 ) {
33     /** Are any already-seen notifications currently filtered out of the shade? */
34     val hasFilteredOutSeenNotifications: StateFlow<Boolean> =
35         notificationListRepository.hasFilteredOutSeenNotifications
36 
37     /** Set whether already-seen notifications are currently filtered out of the shade. */
setHasFilteredOutSeenNotificationsnull38     fun setHasFilteredOutSeenNotifications(value: Boolean) {
39         notificationListRepository.hasFilteredOutSeenNotifications.value = value
40     }
41 
42     /** Set the entry that is identified as the top ongoing notification. */
setTopOngoingNotificationnull43     fun setTopOngoingNotification(entry: NotificationEntry?) {
44         if (NotificationMinimalismPrototype.V2.isUnexpectedlyInLegacyMode()) return
45         notificationListRepository.topOngoingNotificationKey.value = entry?.key
46     }
47 
48     /** Determine if the given notification is the top ongoing notification. */
isTopOngoingNotificationnull49     fun isTopOngoingNotification(entry: NotificationEntry?): Boolean =
50         if (NotificationMinimalismPrototype.V2.isUnexpectedlyInLegacyMode()) false
51         else
52             entry != null && notificationListRepository.topOngoingNotificationKey.value == entry.key
53 
54     /** Set the entry that is identified as the top unseen notification. */
55     fun setTopUnseenNotification(entry: NotificationEntry?) {
56         if (NotificationMinimalismPrototype.V2.isUnexpectedlyInLegacyMode()) return
57         notificationListRepository.topUnseenNotificationKey.value = entry?.key
58     }
59 
60     /** Determine if the given notification is the top unseen notification. */
isTopUnseenNotificationnull61     fun isTopUnseenNotification(entry: NotificationEntry?): Boolean =
62         if (NotificationMinimalismPrototype.V2.isUnexpectedlyInLegacyMode()) false
63         else entry != null && notificationListRepository.topUnseenNotificationKey.value == entry.key
64 }
65