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