1 /*
2  * Copyright (C) 2018 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.car.notification.template;
18 
19 import android.annotation.ColorInt;
20 import android.content.Context;
21 import android.view.View;
22 import android.widget.TextView;
23 
24 import com.android.car.notification.AlertEntry;
25 import com.android.car.notification.NotificationClickHandlerFactory;
26 import com.android.car.notification.NotificationGroup;
27 import com.android.car.notification.NotificationUtils;
28 import com.android.car.notification.R;
29 
30 import java.util.List;
31 
32 /**
33  * Group summary notification view template that displays an automatically generated
34  * group summary notification.
35  */
36 public class GroupSummaryNotificationViewHolder extends CarNotificationBaseViewHolder {
37     private final TextView mTitle1View;
38     private final TextView mTitle2View;
39     private final Context mContext;
40     @ColorInt
41     private final int mCardBackgroundColor;
42     @ColorInt
43     private final int mDefaultTextColor;
44 
45     /**
46      * Constructor of the GroupSummaryNotificationViewHolder with a group summary template view.
47      *
48      * @param view group summary template view supplied by the adapter
49      * @param clickHandlerFactory factory to generate onClickListener
50      */
GroupSummaryNotificationViewHolder( View view, NotificationClickHandlerFactory clickHandlerFactory)51     public GroupSummaryNotificationViewHolder(
52             View view, NotificationClickHandlerFactory clickHandlerFactory) {
53         super(view, clickHandlerFactory);
54         mContext = view.getContext();
55         mCardBackgroundColor = NotificationUtils.getAttrColor(mContext, android.R.attr.colorPrimary);
56         mDefaultTextColor = NotificationUtils.getAttrColor(mContext, android.R.attr.textColorPrimary);
57         mTitle1View = view.findViewById(R.id.child_notification_title_1);
58         mTitle2View = view.findViewById(R.id.child_notification_title_2);
59     }
60 
61     /**
62      * Binds a {@link NotificationGroup} to a group summary notification template.
63      *
64      * <p> Group summary notification view holder is special in that it binds a
65      * {@link NotificationGroup} instead of a {@link AlertEntry}, therefore the standard
66      * bind() method is not used. Still calling super.bind() because the touch events/animations
67      * need to work.
68      */
bind(NotificationGroup notificationGroup)69     public void bind(NotificationGroup notificationGroup) {
70         // isInGroup is always true for group summaries
71         super.bind(notificationGroup.getSingleNotification(), /* isInGroup= */ true, false);
72 
73         List<String> titles = notificationGroup.getChildTitles();
74 
75         if (titles == null || titles.isEmpty()) {
76             return;
77         }
78         mTitle1View.setVisibility(View.VISIBLE);
79         mTitle1View.setText(titles.get(0));
80 
81         if (titles.size() <= 1) {
82             return;
83         }
84         mTitle2View.setVisibility(View.VISIBLE);
85         mTitle2View.setText(titles.get(1));
86     }
87 
88     /**
89      * Resets the notification view empty for recycling.
90      */
91     @Override
reset()92     void reset() {
93         super.reset();
94         mTitle1View.setText(null);
95         mTitle1View.setVisibility(View.GONE);
96 
97         mTitle2View.setText(null);
98         mTitle2View.setVisibility(View.GONE);
99     }
100 }
101