• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.car.notification.template;
17 
18 import android.annotation.CallSuper;
19 import android.content.Context;
20 import android.view.View;
21 import android.widget.Button;
22 import android.widget.TextView;
23 
24 import androidx.recyclerview.widget.RecyclerView;
25 
26 import com.android.car.notification.CarNotificationItemController;
27 import com.android.car.notification.R;
28 
29 /**
30  * Header template for the notification shade. This templates supports the clear all button with id
31  * clear_all_button, a header text with id notification_header_text when the notification list is
32  * not empty and a secondary header text with id empty_notification_header_text when notification
33  * list is empty.
34  */
35 public class CarNotificationHeaderViewHolder extends RecyclerView.ViewHolder {
36     private final TextView mNotificationHeaderText;
37     private final Button mClearAllButton;
38     private final CarNotificationItemController mNotificationItemController;
39     private final boolean mShowHeader;
40 
CarNotificationHeaderViewHolder(Context context, View view, CarNotificationItemController notificationItemController)41     public CarNotificationHeaderViewHolder(Context context, View view,
42             CarNotificationItemController notificationItemController) {
43         super(view);
44 
45         if (notificationItemController == null) {
46             throw new IllegalArgumentException(
47                     "com.android.car.notification.template.CarNotificationHeaderViewHolder did not "
48                             + "receive NotificationItemController from the Adapter.");
49         }
50 
51         mNotificationHeaderText = view.findViewById(R.id.notification_header_text);
52         mClearAllButton = view.findViewById(R.id.clear_all_button);
53         mShowHeader = context.getResources().getBoolean(R.bool.config_showHeaderForNotifications);
54         mNotificationItemController = notificationItemController;
55     }
56 
57     @CallSuper
bind(boolean containsNotification)58     public void bind(boolean containsNotification) {
59         if (containsNotification && mShowHeader) {
60             mNotificationHeaderText.setVisibility(View.VISIBLE);
61 
62             if (mClearAllButton == null) {
63                 return;
64             }
65 
66             mClearAllButton.setVisibility(View.VISIBLE);
67             if (!mClearAllButton.hasOnClickListeners()) {
68                 mClearAllButton.setOnClickListener(view -> {
69                     mNotificationItemController.clearAllNotifications();
70                 });
71             }
72             return;
73         }
74 
75         mNotificationHeaderText.setVisibility(View.GONE);
76 
77         if (mClearAllButton != null) {
78             mClearAllButton.setVisibility(View.GONE);
79         }
80     }
81 }
82