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.content.Intent; 21 import android.os.UserHandle; 22 import android.provider.Settings; 23 import android.view.View; 24 import android.widget.Button; 25 26 import androidx.recyclerview.widget.RecyclerView; 27 28 import com.android.car.notification.CarNotificationItemController; 29 import com.android.car.notification.NotificationClickHandlerFactory; 30 import com.android.car.notification.NotificationUtils; 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 private final float mAlpha; 45 private final boolean mCollapsePanelAfterManageButton; 46 CarNotificationFooterViewHolder(Context context, View view, CarNotificationItemController notificationItemController, NotificationClickHandlerFactory notificationClickHandlerFactory)47 public CarNotificationFooterViewHolder(Context context, View view, 48 CarNotificationItemController notificationItemController, 49 NotificationClickHandlerFactory notificationClickHandlerFactory) { 50 super(view); 51 52 if (notificationItemController == null) { 53 throw new IllegalArgumentException( 54 "com.android.car.notification.template.CarNotificationFooterViewHolder did not " 55 + "receive NotificationItemController from the Adapter."); 56 } 57 58 mContext = context; 59 mClickHandlerFactory = notificationClickHandlerFactory; 60 mShowFooter = context.getResources().getBoolean(R.bool.config_showFooterForNotifications); 61 mClearAllButton = view.findViewById(R.id.clear_all_button); 62 mNotificationItemController = notificationItemController; 63 mShowRecentsAndOlderHeaders = 64 context.getResources().getBoolean(R.bool.config_showRecentAndOldHeaders); 65 mAlpha = context.getResources().getFloat(R.dimen.config_olderNotificationsAlpha); 66 mCollapsePanelAfterManageButton = context.getResources().getBoolean( 67 R.bool.config_collapseShadePanelAfterManageButtonPress); 68 } 69 70 @CallSuper bind(boolean containsNotification, boolean containsSeenNotifications)71 public void bind(boolean containsNotification, boolean containsSeenNotifications) { 72 if (mClearAllButton == null || !mShowFooter) { 73 return; 74 } 75 76 if (containsNotification) { 77 mClearAllButton.setVisibility(View.VISIBLE); 78 if (mShowRecentsAndOlderHeaders) { 79 mClearAllButton.setId(R.id.manage_button); 80 mClearAllButton.setText(R.string.manage_text); 81 mClearAllButton.setOnClickListener(this::manageButtonOnClickListener); 82 mClearAllButton.setAlpha(containsSeenNotifications ? mAlpha : 1); 83 } else { 84 mClearAllButton.setOnClickListener( 85 view -> mNotificationItemController.clearAllNotifications()); 86 } 87 return; 88 } 89 mClearAllButton.setVisibility(View.GONE); 90 } 91 manageButtonOnClickListener(View v)92 private void manageButtonOnClickListener(View v) { 93 Intent intent = new Intent(Settings.ACTION_NOTIFICATION_SETTINGS); 94 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 95 intent.addCategory(Intent.CATEGORY_DEFAULT); 96 mContext.startActivityAsUser(intent, 97 UserHandle.of(NotificationUtils.getCurrentUser(mContext))); 98 99 if (mClickHandlerFactory != null && mCollapsePanelAfterManageButton) { 100 mClickHandlerFactory.collapsePanel(); 101 } 102 } 103 } 104