1 /* 2 * Copyright (C) 2024 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.scene.domain.resolver 18 19 import com.android.compose.animation.scene.SceneKey 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.dagger.qualifiers.Application 22 import com.android.systemui.scene.shared.model.SceneFamilies 23 import com.android.systemui.scene.shared.model.Scenes 24 import com.android.systemui.shade.domain.interactor.ShadeInteractor 25 import com.android.systemui.shade.shared.model.ShadeMode 26 import dagger.Binds 27 import dagger.Module 28 import dagger.multibindings.IntoSet 29 import javax.inject.Inject 30 import kotlinx.coroutines.CoroutineScope 31 import kotlinx.coroutines.flow.SharingStarted 32 import kotlinx.coroutines.flow.StateFlow 33 import kotlinx.coroutines.flow.map 34 import kotlinx.coroutines.flow.stateIn 35 36 @SysUISingleton 37 class NotifShadeSceneFamilyResolver 38 @Inject 39 constructor( 40 @Application applicationScope: CoroutineScope, 41 shadeInteractor: ShadeInteractor, 42 ) : SceneResolver { 43 override val targetFamily: SceneKey = SceneFamilies.NotifShade 44 45 override val resolvedScene: StateFlow<SceneKey> = 46 shadeInteractor.shadeMode 47 .map(::notifShadeScene) 48 .stateIn( 49 applicationScope, 50 started = SharingStarted.Eagerly, 51 initialValue = notifShadeScene(shadeInteractor.shadeMode.value), 52 ) 53 includesScenenull54 override fun includesScene(scene: SceneKey): Boolean = scene in notifShadeScenes 55 56 private fun notifShadeScene(shadeMode: ShadeMode) = 57 when (shadeMode) { 58 is ShadeMode.Single -> Scenes.Shade 59 is ShadeMode.Dual -> Scenes.NotificationsShade 60 is ShadeMode.Split -> Scenes.Shade 61 } 62 63 companion object { 64 val notifShadeScenes = 65 setOf( 66 Scenes.NotificationsShade, 67 Scenes.Shade, 68 ) 69 } 70 } 71 72 @Module 73 interface NotifShadeSceneFamilyResolverModule { bindResolvernull74 @Binds @IntoSet fun bindResolver(interactor: NotifShadeSceneFamilyResolver): SceneResolver 75 } 76