1 /* <lambda>null2 * 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.qs.ui.viewmodel 18 19 import com.android.compose.animation.scene.Back 20 import com.android.compose.animation.scene.Swipe 21 import com.android.compose.animation.scene.UserAction 22 import com.android.compose.animation.scene.UserActionResult 23 import com.android.compose.animation.scene.UserActionResult.HideOverlay 24 import com.android.compose.animation.scene.UserActionResult.ReplaceByOverlay 25 import com.android.systemui.qs.panels.ui.viewmodel.EditModeViewModel 26 import com.android.systemui.scene.shared.model.Overlays 27 import com.android.systemui.scene.ui.viewmodel.SceneContainerArea 28 import com.android.systemui.scene.ui.viewmodel.UserActionsViewModel 29 import dagger.assisted.AssistedFactory 30 import dagger.assisted.AssistedInject 31 import kotlinx.coroutines.flow.map 32 33 /** Models the UI state for the user actions for navigating to other scenes or overlays. */ 34 class QuickSettingsShadeOverlayActionsViewModel 35 @AssistedInject 36 constructor(private val editModeViewModel: EditModeViewModel) : UserActionsViewModel() { 37 38 override suspend fun hydrateActions(setActions: (Map<UserAction, UserActionResult>) -> Unit) { 39 editModeViewModel.isEditing 40 .map { isEditing -> 41 buildMap { 42 put(Swipe.Up, HideOverlay(Overlays.QuickSettingsShade)) 43 // When editing, back should go back to QS from edit mode (i.e. remain in the 44 // same overlay). 45 if (!isEditing) { 46 put(Back, HideOverlay(Overlays.QuickSettingsShade)) 47 } 48 put( 49 Swipe.Down(fromSource = SceneContainerArea.TopEdgeStartHalf), 50 ReplaceByOverlay(Overlays.NotificationsShade), 51 ) 52 } 53 } 54 .collect { actions -> setActions(actions) } 55 } 56 57 @AssistedFactory 58 interface Factory { 59 fun create(): QuickSettingsShadeOverlayActionsViewModel 60 } 61 } 62