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.ui.viewmodel 18 19 import com.android.compose.animation.scene.Edge 20 import com.android.compose.animation.scene.Swipe 21 import com.android.compose.animation.scene.SwipeDirection 22 import com.android.compose.animation.scene.UserAction 23 import com.android.compose.animation.scene.UserActionResult 24 import com.android.systemui.dagger.SysUISingleton 25 import com.android.systemui.dagger.qualifiers.Application 26 import com.android.systemui.scene.shared.model.SceneFamilies 27 import com.android.systemui.scene.shared.model.TransitionKeys.ToSplitShade 28 import com.android.systemui.shade.domain.interactor.ShadeInteractor 29 import com.android.systemui.shade.shared.model.ShadeMode 30 import javax.inject.Inject 31 import kotlinx.coroutines.CoroutineScope 32 import kotlinx.coroutines.flow.SharingStarted 33 import kotlinx.coroutines.flow.StateFlow 34 import kotlinx.coroutines.flow.map 35 import kotlinx.coroutines.flow.stateIn 36 37 @SysUISingleton 38 class GoneSceneViewModel 39 @Inject 40 constructor( 41 @Application private val applicationScope: CoroutineScope, 42 shadeInteractor: ShadeInteractor, 43 ) { 44 val destinationScenes: StateFlow<Map<UserAction, UserActionResult>> = 45 shadeInteractor.shadeMode 46 .map(::destinationScenes) 47 .stateIn( 48 scope = applicationScope, 49 started = SharingStarted.WhileSubscribed(), 50 initialValue = 51 destinationScenes( 52 shadeMode = shadeInteractor.shadeMode.value, 53 ) 54 ) 55 destinationScenesnull56 private fun destinationScenes( 57 shadeMode: ShadeMode, 58 ): Map<UserAction, UserActionResult> { 59 return buildMap { 60 if ( 61 shadeMode is ShadeMode.Single || 62 // TODO(b/338577208): Remove this once we add Dual Shade invocation zones. 63 shadeMode is ShadeMode.Dual 64 ) { 65 put( 66 Swipe( 67 pointerCount = 2, 68 fromSource = Edge.Top, 69 direction = SwipeDirection.Down, 70 ), 71 UserActionResult(SceneFamilies.QuickSettings) 72 ) 73 } 74 75 put( 76 Swipe(direction = SwipeDirection.Down), 77 UserActionResult( 78 SceneFamilies.NotifShade, 79 ToSplitShade.takeIf { shadeMode is ShadeMode.Split } 80 ) 81 ) 82 } 83 } 84 } 85