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.listbuilder.NotifSection 22 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSectioner 23 import javax.inject.Inject 24 25 /** 26 * A class which is used to classify the sections. 27 * NOTE: This class exists to avoid putting metadata like "isMinimized" on the NotifSection 28 */ 29 @SysUISingleton 30 class SectionStyleProvider @Inject constructor() { 31 private lateinit var silentSections: Set<NotifSectioner> 32 private lateinit var lowPrioritySections: Set<NotifSectioner> 33 34 /** 35 * Feed the provider the information it needs about which sections should have minimized top 36 * level views, so that it can calculate the correct minimized state. 37 */ 38 fun setMinimizedSections(sections: Collection<NotifSectioner>) { 39 lowPrioritySections = sections.toSet() 40 } 41 42 /** 43 * Determine if the given section is minimized. 44 */ 45 fun isMinimizedSection(section: NotifSection): Boolean { 46 return lowPrioritySections.contains(section.sectioner) 47 } 48 49 /** 50 * Determine if the given entry is minimized. 51 */ 52 @JvmOverloads 53 fun isMinimized(entry: ListEntry, ifNotInSection: Boolean = true): Boolean { 54 val section = entry.section ?: return ifNotInSection 55 return isMinimizedSection(section) 56 } 57 58 /** 59 * Feed the provider the information it needs about which sections are silent, so that it can 60 * calculate which entries are in a "silent" section. 61 */ 62 fun setSilentSections(sections: Collection<NotifSectioner>) { 63 silentSections = sections.toSet() 64 } 65 66 /** 67 * Determine if the given section is silent. 68 */ 69 fun isSilentSection(section: NotifSection): Boolean { 70 return silentSections.contains(section.sectioner) 71 } 72 73 /** 74 * Determine if the given entry is silent. 75 */ 76 @JvmOverloads 77 fun isSilent(entry: ListEntry, ifNotInSection: Boolean = true): Boolean { 78 val section = entry.section ?: return ifNotInSection 79 return isSilentSection(section) 80 } 81 } 82