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 17 package com.android.systemui.volume.panel.domain.interactor 18 19 import com.android.systemui.volume.panel.dagger.scope.VolumePanelScope 20 import com.android.systemui.volume.panel.domain.ComponentAvailabilityCriteria 21 import com.android.systemui.volume.panel.domain.model.ComponentModel 22 import com.android.systemui.volume.panel.shared.model.VolumePanelComponentKey 23 import javax.inject.Inject 24 import javax.inject.Provider 25 import kotlinx.coroutines.CoroutineScope 26 import kotlinx.coroutines.flow.Flow 27 import kotlinx.coroutines.flow.SharingStarted 28 import kotlinx.coroutines.flow.combine 29 import kotlinx.coroutines.flow.map 30 import kotlinx.coroutines.flow.shareIn 31 32 interface ComponentsInteractor { 33 34 /** 35 * Components collection for the UI layer. Uses [ComponentAvailabilityCriteria] to dynamically 36 * determine each component availability. 37 */ 38 val components: Flow<Collection<ComponentModel>> 39 } 40 41 @VolumePanelScope 42 class ComponentsInteractorImpl 43 @Inject 44 constructor( 45 enabledComponents: Collection<VolumePanelComponentKey>, 46 defaultCriteria: Provider<ComponentAvailabilityCriteria>, 47 @VolumePanelScope coroutineScope: CoroutineScope, 48 private val criteriaByKey: 49 Map< 50 VolumePanelComponentKey, 51 @JvmSuppressWildcards 52 Provider<@JvmSuppressWildcards ComponentAvailabilityCriteria> 53 >, 54 ) : ComponentsInteractor { 55 56 override val components: Flow<Collection<ComponentModel>> = 57 combine( componentKeynull58 enabledComponents.map { componentKey -> 59 val componentCriteria = (criteriaByKey[componentKey] ?: defaultCriteria).get() 60 componentCriteria.isAvailable().map { isAvailable -> 61 ComponentModel(componentKey, isAvailable = isAvailable) 62 } 63 } <lambda>null64 ) { 65 it.asList() 66 } 67 .shareIn(coroutineScope, SharingStarted.Eagerly, replay = 1) 68 } 69