1 /* 2 * Copyright (C) 2020 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 18 19 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection 20 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifFilter 21 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifPromoter 22 23 /** 24 * Stores the state that [ShadeListBuilder] assigns to this [ListEntry] 25 */ 26 data class ListAttachState private constructor( 27 /** 28 * Null if not attached to the current shade list. If top-level, then the shade list root. If 29 * part of a group, then that group's GroupEntry. 30 */ 31 var parent: GroupEntry?, 32 33 /** 34 * The section that this ListEntry was sorted into. If the child of the group, this will be the 35 * parent's section. Null if not attached to the list. 36 */ 37 var section: NotifSection?, 38 39 /** 40 * If a [NotifFilter] is excluding this entry from the list, then that filter. Always null for 41 * [GroupEntry]s. 42 */ 43 var excludingFilter: NotifFilter?, 44 45 /** 46 * The [NotifPromoter] promoting this entry to top-level, if any. Always null for [GroupEntry]s. 47 */ 48 var promoter: NotifPromoter?, 49 50 /** 51 * If an entry's group was pruned from the list by NotifPipeline logic, the reason is here. 52 */ 53 var groupPruneReason: String?, 54 55 /** 56 * If the [VisualStabilityManager] is suppressing group or section changes for this entry, 57 * suppressedChanges will contain the new parent or section that we would have assigned to 58 * the entry had it not been suppressed by the VisualStabilityManager. 59 */ 60 var suppressedChanges: SuppressedAttachState 61 ) { 62 63 /** 64 * Identifies the notification order in the entire notification list. 65 * NOTE: this property is intentionally excluded from equals calculation (by not making it a 66 * constructor arg) because its value changes based on the presence of other members in the 67 * list, rather than anything having to do with this entry's attachment. 68 */ 69 var stableIndex: Int = -1 70 71 /** Access the index of the [section] or -1 if the entry does not have one */ 72 val sectionIndex: Int get() = section?.index ?: -1 73 74 /** Copies the state of another instance. */ clonenull75 fun clone(other: ListAttachState) { 76 parent = other.parent 77 section = other.section 78 excludingFilter = other.excludingFilter 79 promoter = other.promoter 80 groupPruneReason = other.groupPruneReason 81 suppressedChanges.clone(other.suppressedChanges) 82 stableIndex = other.stableIndex 83 } 84 85 /** Resets back to a "clean" state (the same as created by the factory method) */ resetnull86 fun reset() { 87 parent = null 88 section = null 89 excludingFilter = null 90 promoter = null 91 groupPruneReason = null 92 suppressedChanges.reset() 93 stableIndex = -1 94 } 95 96 /** 97 * Erases bookkeeping traces stored on an entry when it is removed from the notif list. 98 * This can happen if the entry is removed from a group that was broken up or if the entry was 99 * filtered out during any of the filtering steps. 100 */ detachnull101 fun detach() { 102 parent = null 103 section = null 104 promoter = null 105 stableIndex = -1 106 } 107 108 companion object { 109 @JvmStatic createnull110 fun create(): ListAttachState { 111 return ListAttachState( 112 null, 113 null, 114 null, 115 null, 116 null, 117 SuppressedAttachState.create() 118 ) 119 } 120 } 121 } 122