• 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 com.android.systemui.statusbar.notification.collection.GroupEntry
20 import com.android.systemui.statusbar.notification.collection.ListEntry
21 import com.android.systemui.statusbar.notification.collection.NotifLiveDataStoreImpl
22 import com.android.systemui.statusbar.notification.collection.NotifPipeline
23 import com.android.systemui.statusbar.notification.collection.NotificationEntry
24 import com.android.systemui.statusbar.notification.collection.coordinator.dagger.CoordinatorScope
25 import com.android.systemui.statusbar.notification.collection.render.requireSummary
26 import javax.inject.Inject
27 
28 /**
29  * A small coordinator which updates the notif stack (the view layer which holds notifications)
30  * with high-level data after the stack is populated with the final entries.
31  */
32 @CoordinatorScope
33 class DataStoreCoordinator @Inject internal constructor(
34     private val notifLiveDataStoreImpl: NotifLiveDataStoreImpl
35 ) : Coordinator {
36 
37     override fun attach(pipeline: NotifPipeline) {
38         pipeline.addOnAfterRenderListListener { entries, _ -> onAfterRenderList(entries) }
39     }
40 
41     fun onAfterRenderList(entries: List<ListEntry>) {
42         val flatEntryList = flattenedEntryList(entries)
43         notifLiveDataStoreImpl.setActiveNotifList(flatEntryList)
44     }
45 
46     private fun flattenedEntryList(entries: List<ListEntry>) =
47         mutableListOf<NotificationEntry>().also { list ->
48             entries.forEach { entry ->
49                 when (entry) {
50                     is NotificationEntry -> list.add(entry)
51                     is GroupEntry -> {
52                         list.add(entry.requireSummary)
53                         list.addAll(entry.children)
54                     }
55                     else -> error("Unexpected entry $entry")
56                 }
57             }
58         }
59 }