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.app.ActivityManager; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.UserHandle; 23 import android.provider.Settings; 24 import android.view.View; 25 import android.widget.Button; 26 27 import androidx.recyclerview.widget.RecyclerView; 28 29 import com.android.car.notification.CarNotificationItemController; 30 import com.android.car.notification.NotificationClickHandlerFactory; 31 import com.android.car.notification.R; 32 33 /** 34 * Footer template for the notification shade. This templates supports the clear all button with id 35 * clear_all_button. 36 */ 37 public class CarNotificationFooterViewHolder extends RecyclerView.ViewHolder { 38 private final Context mContext; 39 private final Button mClearAllButton; 40 private final CarNotificationItemController mNotificationItemController; 41 private final boolean mShowFooter; 42 private final boolean mShowRecentsAndOlderHeaders; 43 private final NotificationClickHandlerFactory mClickHandlerFactory; 44 CarNotificationFooterViewHolder(Context context, View view, CarNotificationItemController notificationItemController, NotificationClickHandlerFactory notificationClickHandlerFactory)45 public CarNotificationFooterViewHolder(Context context, View view, 46 CarNotificationItemController notificationItemController, 47 NotificationClickHandlerFactory notificationClickHandlerFactory) { 48 super(view); 49 50 if (notificationItemController == null) { 51 throw new IllegalArgumentException( 52 "com.android.car.notification.template.CarNotificationFooterViewHolder did not " 53 + "receive NotificationItemController from the Adapter."); 54 } 55 56 mContext = context; 57 mClickHandlerFactory = notificationClickHandlerFactory; 58 mShowFooter = context.getResources().getBoolean(R.bool.config_showFooterForNotifications); 59 mClearAllButton = view.findViewById(R.id.clear_all_button); 60 mNotificationItemController = notificationItemController; 61 mShowRecentsAndOlderHeaders = 62 context.getResources().getBoolean(R.bool.config_showRecentAndOldHeaders); 63 } 64 65 @CallSuper bind(boolean containsNotification)66 public void bind(boolean containsNotification) { 67 if (mClearAllButton == null || !mShowFooter) { 68 return; 69 } 70 71 if (containsNotification) { 72 mClearAllButton.setVisibility(View.VISIBLE); 73 if (mShowRecentsAndOlderHeaders) { 74 mClearAllButton.setText(R.string.manage_text); 75 if (!mClearAllButton.hasOnClickListeners()) { 76 mClearAllButton.setOnClickListener(this::manageButtonOnClickListener); 77 } 78 } else { 79 if (!mClearAllButton.hasOnClickListeners()) { 80 mClearAllButton.setOnClickListener(view -> { 81 mNotificationItemController.clearAllNotifications(); 82 }); 83 } 84 } 85 return; 86 } 87 mClearAllButton.setVisibility(View.GONE); 88 } 89 manageButtonOnClickListener(View v)90 private void manageButtonOnClickListener(View v) { 91 Intent intent = new Intent(Settings.ACTION_NOTIFICATION_SETTINGS); 92 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 93 intent.addCategory(Intent.CATEGORY_DEFAULT); 94 mContext.startActivityAsUser(intent, UserHandle.of(ActivityManager.getCurrentUser())); 95 96 if (mClickHandlerFactory != null) mClickHandlerFactory.collapsePanel(); 97 } 98 } 99