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