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