1 /*
2  * Copyright (C) 2019 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 
20 import androidx.annotation.Nullable;
21 
22 import com.android.systemui.statusbar.notification.collection.listbuilder.pluggable.NotifSection;
23 
24 /**
25  * Abstract superclass for top-level entries, i.e. things that can appear in the final notification
26  * list shown to users. In practice, this means either GroupEntries or NotificationEntries.
27  */
28 public abstract class ListEntry {
29     private final String mKey;
30 
31     int mFirstAddedIteration = -1;
32 
33     private final ListAttachState mPreviousAttachState = ListAttachState.create();
34     private final ListAttachState mAttachState = ListAttachState.create();
35 
ListEntry(String key)36     ListEntry(String key) {
37         mKey = key;
38     }
39 
getKey()40     public String getKey() {
41         return mKey;
42     }
43 
44     /**
45      * Should return the "representative entry" for this ListEntry. For NotificationEntries, its
46      * the entry itself. For groups, it should be the summary (but if a summary doesn't exist,
47      * this can return null). This method exists to interface with
48      * legacy code that expects groups to also be NotificationEntries.
49      */
getRepresentativeEntry()50     public abstract @Nullable NotificationEntry getRepresentativeEntry();
51 
getParent()52     @Nullable public GroupEntry getParent() {
53         return mAttachState.getParent();
54     }
55 
setParent(@ullable GroupEntry parent)56     void setParent(@Nullable GroupEntry parent) {
57         mAttachState.setParent(parent);
58     }
59 
getPreviousParent()60     @Nullable public GroupEntry getPreviousParent() {
61         return mPreviousAttachState.getParent();
62     }
63 
64     /** The section this notification was assigned to (0 to N-1, where N is number of sections). */
getSection()65     public int getSection() {
66         return mAttachState.getSectionIndex();
67     }
68 
getNotifSection()69     @Nullable public NotifSection getNotifSection() {
70         return mAttachState.getSection();
71     }
72 
getAttachState()73     ListAttachState getAttachState() {
74         return mAttachState;
75     }
76 
getPreviousAttachState()77     ListAttachState getPreviousAttachState() {
78         return mPreviousAttachState;
79     }
80 
81     /**
82      * Stores the current attach state into {@link #getPreviousAttachState()}} and then starts a
83      * fresh attach state (all entries will be null/default-initialized).
84      */
beginNewAttachState()85     void beginNewAttachState() {
86         mPreviousAttachState.clone(mAttachState);
87         mAttachState.reset();
88     }
89 }
90