1 /* <lambda>null2 * Copyright (C) 2023 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.systemui.statusbar.notification.icon.ui.viewmodel 17 18 import com.android.systemui.dagger.qualifiers.Background 19 import com.android.systemui.statusbar.notification.icon.domain.interactor.NotificationIconsInteractor 20 import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconsViewData.LimitType 21 import javax.inject.Inject 22 import kotlin.coroutines.CoroutineContext 23 import kotlinx.coroutines.flow.Flow 24 import kotlinx.coroutines.flow.conflate 25 import kotlinx.coroutines.flow.distinctUntilChanged 26 import kotlinx.coroutines.flow.flowOn 27 import kotlinx.coroutines.flow.map 28 29 /** View-model for the overflow row of notification icons displayed in the notification shade. */ 30 class NotificationIconContainerShelfViewModel 31 @Inject 32 constructor( 33 @Background bgContext: CoroutineContext, 34 interactor: NotificationIconsInteractor, 35 ) { 36 /** [NotificationIconsViewData] indicating which icons to display in the view. */ 37 val icons: Flow<NotificationIconsViewData> = 38 interactor 39 .filteredNotifSet() 40 .map { entries -> 41 var firstAmbient = 0 42 val visibleKeys = buildList { 43 for (entry in entries) { 44 entry.toIconInfo(entry.shelfIcon)?.let { info -> 45 add(info) 46 // NOTE: we assume that all ambient notifications will be at the end of 47 // the list 48 if (!entry.isAmbient) { 49 firstAmbient++ 50 } 51 } 52 } 53 } 54 NotificationIconsViewData( 55 visibleKeys, 56 iconLimit = firstAmbient, 57 limitType = LimitType.MaximumIndex, 58 ) 59 } 60 .flowOn(bgContext) 61 .conflate() 62 .distinctUntilChanged() 63 } 64