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