1 /* <lambda>null2 * 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 17 package com.android.systemui.statusbar.notification.collection.coordinator 18 19 import android.content.Context 20 import com.android.systemui.res.R 21 import com.android.systemui.statusbar.notification.AssistantFeedbackController 22 import com.android.systemui.statusbar.notification.collection.ListEntry 23 import com.android.systemui.statusbar.notification.collection.NotifPipeline 24 import com.android.systemui.statusbar.notification.collection.NotificationEntry 25 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope 26 import com.android.systemui.statusbar.notification.collection.provider.SectionStyleProvider 27 import com.android.systemui.statusbar.notification.collection.render.NotifRowController 28 import javax.inject.Inject 29 30 /** 31 * A small coordinator which updates the notif rows with data related to the current shade after 32 * they are fully attached. 33 */ 34 @CoordinatorScope 35 class RowAppearanceCoordinator @Inject internal constructor( 36 context: Context, 37 private var mAssistantFeedbackController: AssistantFeedbackController, 38 private var mSectionStyleProvider: SectionStyleProvider 39 ) : Coordinator { 40 41 private var entryToExpand: NotificationEntry? = null 42 43 /** 44 * `true` if notifications not part of a group should by default be rendered in their 45 * expanded state. If `false`, then only the first notification will be expanded if 46 * possible. 47 */ 48 private val mAlwaysExpandNonGroupedNotification = 49 context.resources.getBoolean(R.bool.config_alwaysExpandNonGroupedNotifications) 50 51 /** 52 * `true` if the first non-group expandable notification should be expanded automatically 53 * when possible. If `false`, then the first non-group expandable notification should not 54 * be expanded. 55 */ 56 private val mAutoExpandFirstNotification = 57 context.resources.getBoolean(R.bool.config_autoExpandFirstNotification) 58 59 override fun attach(pipeline: NotifPipeline) { 60 pipeline.addOnBeforeRenderListListener(::onBeforeRenderList) 61 pipeline.addOnAfterRenderEntryListener(::onAfterRenderEntry) 62 } 63 64 private fun onBeforeRenderList(list: List<ListEntry>) { 65 entryToExpand = list.firstOrNull()?.representativeEntry?.takeIf { entry -> 66 !mSectionStyleProvider.isMinimizedSection(entry.section!!) 67 } 68 } 69 70 private fun onAfterRenderEntry(entry: NotificationEntry, controller: NotifRowController) { 71 // If mAlwaysExpandNonGroupedNotification is false, then only expand the 72 // very first notification if it's not a child of grouped notifications and when 73 // mAutoExpandFirstNotification is true. 74 controller.setSystemExpanded(mAlwaysExpandNonGroupedNotification || 75 (mAutoExpandFirstNotification && entry == entryToExpand)) 76 // Show/hide the feedback icon 77 controller.setFeedbackIcon(mAssistantFeedbackController.getFeedbackIcon(entry)) 78 } 79 } 80