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 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import com.android.internal.annotations.VisibleForTesting;
23 import com.android.systemui.statusbar.notification.collection.coordinator.PreparationCoordinator;
24 
25 import java.util.ArrayList;
26 import java.util.Collections;
27 import java.util.Comparator;
28 import java.util.List;
29 
30 /**
31  * Represents a set of grouped notifications. The final notification list is usually a mix of
32  * GroupEntries and NotificationEntries.
33  */
34 public class GroupEntry extends ListEntry {
35     @Nullable private NotificationEntry mSummary;
36     private final List<NotificationEntry> mChildren = new ArrayList<>();
37 
38     private final List<NotificationEntry> mUnmodifiableChildren =
39             Collections.unmodifiableList(mChildren);
40     private int mUntruncatedChildCount;
41 
42     @VisibleForTesting
GroupEntry(String key)43     public GroupEntry(String key) {
44         super(key);
45     }
46 
47     @Override
getRepresentativeEntry()48     public NotificationEntry getRepresentativeEntry() {
49         return mSummary;
50     }
51 
52     @Nullable
getSummary()53     public NotificationEntry getSummary() {
54         return mSummary;
55     }
56 
57     @NonNull
getChildren()58     public List<NotificationEntry> getChildren() {
59         return mUnmodifiableChildren;
60     }
61 
62     @VisibleForTesting
setSummary(@ullable NotificationEntry summary)63     public void setSummary(@Nullable NotificationEntry summary) {
64         mSummary = summary;
65     }
66 
67     /**
68      * @see #getUntruncatedChildCount()
69      */
setUntruncatedChildCount(int childCount)70     public void setUntruncatedChildCount(int childCount) {
71         mUntruncatedChildCount = childCount;
72     }
73 
74     /**
75      * Get the untruncated number of children from the data model, including those that will not
76      * have views bound. This includes children that {@link PreparationCoordinator} will filter out
77      * entirely when they are beyond the last visible child.
78      *
79      * TODO: This should move to some shared class between the model and view hierarchy
80      */
getUntruncatedChildCount()81     public int getUntruncatedChildCount() {
82         return mUntruncatedChildCount;
83     }
84 
clearChildren()85     void clearChildren() {
86         mChildren.clear();
87     }
88 
addChild(NotificationEntry child)89     void addChild(NotificationEntry child) {
90         mChildren.add(child);
91     }
92 
sortChildren(Comparator<? super NotificationEntry> c)93     void sortChildren(Comparator<? super NotificationEntry> c) {
94         mChildren.sort(c);
95     }
96 
getRawChildren()97     List<NotificationEntry> getRawChildren() {
98         return mChildren;
99     }
100 
101     public static final GroupEntry ROOT_ENTRY = new GroupEntry("<root>");
102 
103 }
104