1 /* 2 * Copyright (C) 2021 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.annotation.NonNull; 25 import androidx.recyclerview.widget.RecyclerView; 26 27 import com.android.car.notification.CarNotificationItemController; 28 import com.android.car.notification.R; 29 30 /** 31 * Older Header template for the notification shade. This templates supports the clear all button 32 * with ID clear_all_button, a header text with ID notification_older_text when the notification 33 * list is not empty and has seen notifications. Clear all button is only shown if no unseen 34 * notifications are present. 35 */ 36 public class CarNotificationOlderViewHolder extends RecyclerView.ViewHolder { 37 private final TextView mNotificationOlderText; 38 private final Button mClearAllButton; 39 private final CarNotificationItemController mNotificationItemController; 40 private final boolean mShowOlder; 41 CarNotificationOlderViewHolder(Context context, View view, @NonNull CarNotificationItemController notificationItemController)42 public CarNotificationOlderViewHolder(Context context, View view, 43 @NonNull CarNotificationItemController notificationItemController) { 44 super(view); 45 46 mNotificationOlderText = view.findViewById(R.id.notification_older_text); 47 mClearAllButton = view.findViewById(R.id.clear_all_button); 48 mShowOlder = context.getResources().getBoolean(R.bool.config_showRecentAndOldHeaders); 49 mNotificationItemController = notificationItemController; 50 } 51 52 /** 53 * Sets up {@link CarNotificationOlderViewHolder}'s text and clear button functionality 54 * 55 * @param containsNotification {@code true} if notifications exist under this header 56 * @param showClearAllButton {@code true} if clear button should be visible 57 */ 58 @CallSuper bind(boolean containsNotification, boolean showClearAllButton)59 public void bind(boolean containsNotification, boolean showClearAllButton) { 60 if (containsNotification && mShowOlder) { 61 mNotificationOlderText.setVisibility(View.VISIBLE); 62 63 if (mClearAllButton == null) { 64 return; 65 } 66 67 if (showClearAllButton) { 68 mClearAllButton.setVisibility(View.VISIBLE); 69 if (!mClearAllButton.hasOnClickListeners()) { 70 mClearAllButton.setOnClickListener(view -> { 71 mNotificationItemController.clearAllNotifications(); 72 }); 73 } 74 } else { 75 mClearAllButton.setVisibility(View.GONE); 76 } 77 78 return; 79 } 80 81 mNotificationOlderText.setVisibility(View.GONE); 82 if (mClearAllButton != null) { 83 mClearAllButton.setVisibility(View.GONE); 84 } 85 } 86 } 87