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 androidx.annotation.Nullable;
20 
21 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection;
22 
23 import java.util.ArrayList;
24 import java.util.List;
25 
26 /**
27  * Builder to construct instances of {@link GroupEntry} for tests.
28  */
29 public class GroupEntryBuilder {
30     private String mKey = "test_group_key";
31     private long mCreationTime = 0;
32     @Nullable private GroupEntry mParent = GroupEntry.ROOT_ENTRY;
33     private NotifSection mNotifSection;
34     @Nullable private NotificationEntry mSummary = null;
35     private final List<NotificationEntry> mChildren = new ArrayList<>();
36 
37     /** Builds a new instance of GroupEntry */
build()38     public GroupEntry build() {
39         GroupEntry ge = new GroupEntry(mKey, mCreationTime);
40         ge.setParent(mParent);
41         ge.getAttachState().setSection(mNotifSection);
42 
43         ge.setSummary(mSummary);
44         if (mSummary != null) {
45             mSummary.setParent(ge);
46         }
47 
48         for (NotificationEntry child : mChildren) {
49             ge.addChild(child);
50             child.setParent(ge);
51         }
52         return ge;
53     }
54 
55     /** Sets the group key. */
setKey(String key)56     public GroupEntryBuilder setKey(String key) {
57         mKey = key;
58         return this;
59     }
60 
61     /** Sets the creation time. */
setCreationTime(long creationTime)62     public GroupEntryBuilder setCreationTime(long creationTime) {
63         mCreationTime = creationTime;
64         return this;
65     }
66 
67     /** Sets the parent entry of the group. */
setParent(@ullable GroupEntry entry)68     public GroupEntryBuilder setParent(@Nullable GroupEntry entry) {
69         mParent = entry;
70         return this;
71     }
72 
73     /** Sets the section the group belongs to. */
setSection(@ullable NotifSection section)74     public GroupEntryBuilder setSection(@Nullable NotifSection section) {
75         mNotifSection = section;
76         return this;
77     }
78 
79     /** Sets the group summary. */
setSummary( NotificationEntry summary)80     public GroupEntryBuilder setSummary(
81             NotificationEntry summary) {
82         mSummary = summary;
83         return this;
84     }
85 
86     /** Sets the group children. */
setChildren(List<NotificationEntry> children)87     public GroupEntryBuilder setChildren(List<NotificationEntry> children) {
88         mChildren.clear();
89         mChildren.addAll(children);
90         return this;
91     }
92 
93     /** Adds a child to the existing list of children */
addChild(NotificationEntry entry)94     public GroupEntryBuilder addChild(NotificationEntry entry) {
95         mChildren.add(entry);
96         return this;
97     }
98 
99     /** Get the group's internal children list. */
getRawChildren(GroupEntry groupEntry)100     public static List<NotificationEntry> getRawChildren(GroupEntry groupEntry) {
101         return groupEntry.getRawChildren();
102     }
103 }
104