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 setKey(String key)55 public GroupEntryBuilder setKey(String key) { 56 mKey = key; 57 return this; 58 } 59 setCreationTime(long creationTime)60 public GroupEntryBuilder setCreationTime(long creationTime) { 61 mCreationTime = creationTime; 62 return this; 63 } 64 setParent(@ullable GroupEntry entry)65 public GroupEntryBuilder setParent(@Nullable GroupEntry entry) { 66 mParent = entry; 67 return this; 68 } 69 setSection(@ullable NotifSection section)70 public GroupEntryBuilder setSection(@Nullable NotifSection section) { 71 mNotifSection = section; 72 return this; 73 } 74 setSummary( NotificationEntry summary)75 public GroupEntryBuilder setSummary( 76 NotificationEntry summary) { 77 mSummary = summary; 78 return this; 79 } 80 setChildren(List<NotificationEntry> children)81 public GroupEntryBuilder setChildren(List<NotificationEntry> children) { 82 mChildren.clear(); 83 mChildren.addAll(children); 84 return this; 85 } 86 87 /** Adds a child to the existing list of children */ addChild(NotificationEntry entry)88 public GroupEntryBuilder addChild(NotificationEntry entry) { 89 mChildren.add(entry); 90 return this; 91 } 92 getRawChildren(GroupEntry groupEntry)93 public static List<NotificationEntry> getRawChildren(GroupEntry groupEntry) { 94 return groupEntry.getRawChildren(); 95 } 96 } 97