1 /*
2  * Copyright (C) 2021 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.collection.provider
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.statusbar.notification.collection.ListEntry
21 import com.android.systemui.statusbar.notification.collection.SortBySectionTimeFlag
22 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection
23 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner
24 import com.android.systemui.statusbar.notification.stack.BUCKET_PEOPLE
25 import javax.inject.Inject
26 
27 /**
28  * A class which is used to classify the sections.
29  * NOTE: This class exists to avoid putting metadata like "isMinimized" on the NotifSection
30  */
31 @SysUISingleton
32 class SectionStyleProvider @Inject constructor(
33         private val highPriorityProvider: HighPriorityProvider) {
34     private lateinit var silentSections: Set<NotifSectioner>
35     private lateinit var lowPrioritySections: Set<NotifSectioner>
36 
37     /**
38      * Feed the provider the information it needs about which sections should have minimized top
39      * level views, so that it can calculate the correct minimized state.
40      */
setMinimizedSectionsnull41     fun setMinimizedSections(sections: Collection<NotifSectioner>) {
42         lowPrioritySections = sections.toSet()
43     }
44 
45     /**
46      * Determine if the given section is minimized.
47      */
isMinimizedSectionnull48     fun isMinimizedSection(section: NotifSection): Boolean {
49         return lowPrioritySections.contains(section.sectioner)
50     }
51 
52     /**
53      * Determine if the given entry is minimized.
54      */
55     @JvmOverloads
isMinimizednull56     fun isMinimized(entry: ListEntry, ifNotInSection: Boolean = true): Boolean {
57         val section = entry.section ?: return ifNotInSection
58         return isMinimizedSection(section)
59     }
60 
61     /**
62      * Feed the provider the information it needs about which sections are silent, so that it can
63      * calculate which entries are in a "silent" section.
64      */
setSilentSectionsnull65     fun setSilentSections(sections: Collection<NotifSectioner>) {
66         silentSections = sections.toSet()
67     }
68 
69     /**
70      * Determine if the given section is silent.
71      */
isSilentSectionnull72     fun isSilentSection(section: NotifSection): Boolean {
73         return silentSections.contains(section.sectioner)
74     }
75 
76     /**
77      * Determine if the given entry is silent.
78      */
79     @JvmOverloads
isSilentnull80     fun isSilent(entry: ListEntry, ifNotInSection: Boolean = true): Boolean {
81         val section = entry.section ?: return ifNotInSection
82         if (SortBySectionTimeFlag.isEnabled) {
83             if (entry.section?.bucket == BUCKET_PEOPLE) {
84                 return !highPriorityProvider.isHighPriorityConversation(entry)
85             }
86             return isSilentSection(section)
87         } else {
88             return isSilentSection(section)
89         }
90     }
91 }
92