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.qs.ui.viewmodel 18 19 import com.android.systemui.lifecycle.ExclusiveActivatable 20 import com.android.systemui.scene.domain.interactor.SceneInteractor 21 import com.android.systemui.shade.domain.interactor.ShadeInteractor 22 import com.android.systemui.statusbar.notification.stack.domain.interactor.NotificationStackAppearanceInteractor 23 import com.android.systemui.statusbar.notification.stack.shared.model.ShadeScrimShape 24 import dagger.assisted.AssistedFactory 25 import dagger.assisted.AssistedInject 26 import kotlinx.coroutines.awaitCancellation 27 import kotlinx.coroutines.coroutineScope 28 import kotlinx.coroutines.flow.distinctUntilChanged 29 import kotlinx.coroutines.flow.filter 30 import kotlinx.coroutines.launch 31 32 /** 33 * Models UI state used to render the content of the quick settings shade overlay. 34 * 35 * Different from [QuickSettingsShadeOverlayActionsViewModel], which only models user actions that 36 * can be performed to navigate to other scenes. 37 */ 38 class QuickSettingsShadeOverlayContentViewModel 39 @AssistedInject 40 constructor( 41 val shadeInteractor: ShadeInteractor, 42 val sceneInteractor: SceneInteractor, 43 val notificationStackAppearanceInteractor: NotificationStackAppearanceInteractor, 44 ) : ExclusiveActivatable() { 45 onActivatednull46 override suspend fun onActivated(): Nothing { 47 coroutineScope { 48 launch { 49 shadeInteractor.isShadeTouchable 50 .distinctUntilChanged() 51 .filter { !it } 52 .collect { 53 shadeInteractor.collapseQuickSettingsShade( 54 loggingReason = "device became non-interactive" 55 ) 56 } 57 } 58 } 59 60 awaitCancellation() 61 } 62 63 /** Notifies that the bounds of the QuickSettings panel have changed. */ onPanelShapeChangednull64 fun onPanelShapeChanged(shape: ShadeScrimShape?) { 65 notificationStackAppearanceInteractor.sendQsPanelShape(shape) 66 } 67 onScrimClickednull68 fun onScrimClicked() { 69 shadeInteractor.collapseQuickSettingsShade(loggingReason = "shade scrim clicked") 70 } 71 72 @AssistedFactory 73 interface Factory { createnull74 fun create(): QuickSettingsShadeOverlayContentViewModel 75 } 76 } 77