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 java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.List;
26 
27 /**
28  * Represents a set of grouped notifications. The final notification list is usually a mix of
29  * GroupEntries and NotificationEntries.
30  */
31 public class GroupEntry extends ListEntry {
32     @Nullable private NotificationEntry mSummary;
33     private final List<NotificationEntry> mChildren = new ArrayList<>();
34 
35     private final List<NotificationEntry> mUnmodifiableChildren =
36             Collections.unmodifiableList(mChildren);
37     private int mUntruncatedChildCount;
38 
GroupEntry(String key, long creationTime)39     GroupEntry(String key, long creationTime) {
40         super(key, creationTime);
41     }
42 
43     @Override
getRepresentativeEntry()44     public NotificationEntry getRepresentativeEntry() {
45         return mSummary;
46     }
47 
48     @Nullable
getSummary()49     public NotificationEntry getSummary() {
50         return mSummary;
51     }
52 
53     @NonNull
getChildren()54     public List<NotificationEntry> getChildren() {
55         return mUnmodifiableChildren;
56     }
57 
setSummary(@ullable NotificationEntry summary)58     void setSummary(@Nullable NotificationEntry summary) {
59         mSummary = summary;
60     }
61 
clearChildren()62     void clearChildren() {
63         mChildren.clear();
64     }
65 
addChild(NotificationEntry child)66     void addChild(NotificationEntry child) {
67         mChildren.add(child);
68     }
69 
sortChildren(Comparator<? super NotificationEntry> c)70     void sortChildren(Comparator<? super NotificationEntry> c) {
71         mChildren.sort(c);
72     }
73 
getRawChildren()74     List<NotificationEntry> getRawChildren() {
75         return mChildren;
76     }
77 
78     public static final GroupEntry ROOT_ENTRY = new GroupEntry("<root>", 0);
79 
80 }
81