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.shade.ui.viewmodel 18 19 import com.android.compose.animation.scene.Swipe 20 import com.android.compose.animation.scene.UserAction 21 import com.android.compose.animation.scene.UserActionResult 22 import com.android.systemui.qs.ui.adapter.QSSceneAdapter 23 import com.android.systemui.scene.domain.interactor.SceneBackInteractor 24 import com.android.systemui.scene.shared.model.SceneFamilies 25 import com.android.systemui.scene.shared.model.Scenes 26 import com.android.systemui.scene.shared.model.TransitionKeys.ToSplitShade 27 import com.android.systemui.scene.ui.viewmodel.UserActionsViewModel 28 import com.android.systemui.shade.domain.interactor.ShadeModeInteractor 29 import com.android.systemui.shade.shared.model.ShadeMode 30 import dagger.assisted.AssistedFactory 31 import dagger.assisted.AssistedInject 32 import kotlinx.coroutines.flow.combine 33 import kotlinx.coroutines.flow.filter 34 import kotlinx.coroutines.flow.map 35 36 /** 37 * Models the UI state for the user actions that the user can perform to navigate to other scenes. 38 * 39 * Different from the [ShadeSceneContentViewModel] which models the _content_ of the scene. 40 */ 41 class ShadeUserActionsViewModel 42 @AssistedInject 43 constructor( 44 private val qsSceneAdapter: QSSceneAdapter, 45 private val shadeModeInteractor: ShadeModeInteractor, 46 private val sceneBackInteractor: SceneBackInteractor, 47 ) : UserActionsViewModel() { 48 49 override suspend fun hydrateActions(setActions: (Map<UserAction, UserActionResult>) -> Unit) { 50 combine( 51 shadeModeInteractor.shadeMode, 52 qsSceneAdapter.isCustomizerShowing, 53 sceneBackInteractor.backScene 54 .filter { it != Scenes.Shade } 55 .map { it ?: SceneFamilies.Home }, 56 ) { shadeMode, isCustomizerShowing, backScene -> 57 buildMap<UserAction, UserActionResult> { 58 if (!isCustomizerShowing) { 59 set( 60 Swipe.Up, 61 UserActionResult( 62 backScene, 63 ToSplitShade.takeIf { shadeMode is ShadeMode.Split }, 64 ), 65 ) 66 } 67 68 // TODO(b/330200163) Add an else to be able to collapse the shade while 69 // customizing 70 if (shadeMode is ShadeMode.Single) { 71 set(Swipe.Down, UserActionResult(Scenes.QuickSettings)) 72 } 73 } 74 } 75 .collect { actions -> setActions(actions) } 76 } 77 78 @AssistedFactory 79 interface Factory { 80 fun create(): ShadeUserActionsViewModel 81 } 82 } 83