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.panels.ui.viewmodel 18 19 import androidx.compose.runtime.Stable 20 import androidx.compose.runtime.getValue 21 import androidx.compose.runtime.mutableStateOf 22 import com.android.systemui.dagger.SysUISingleton 23 import com.android.systemui.plugins.qs.TileDetailsViewModel 24 import com.android.systemui.qs.pipeline.domain.interactor.CurrentTilesInteractor 25 import com.android.systemui.qs.pipeline.shared.TileSpec 26 import com.android.systemui.shade.domain.interactor.ShadeModeInteractor 27 import javax.inject.Inject 28 29 @SysUISingleton 30 @Stable 31 class DetailsViewModel @Inject constructor( 32 val currentTilesInteractor: CurrentTilesInteractor, 33 val shadeModeInteractor: ShadeModeInteractor 34 ) { 35 36 /** 37 * The current active [TileDetailsViewModel]. If it's `null`, it means the qs overlay is not 38 * showing any details view. It changes when [onTileClicked] and [closeDetailedView]. 39 */ 40 private val _activeTileDetails = mutableStateOf<TileDetailsViewModel?>(null) 41 val activeTileDetails by _activeTileDetails 42 43 /** 44 * Update the active [TileDetailsViewModel] to `null`. 45 * 46 * @see activeTileDetails 47 */ 48 fun closeDetailedView() { 49 _activeTileDetails.value = null 50 } 51 52 /** 53 * Update the active [TileDetailsViewModel] to the `spec`'s corresponding view model. Return if 54 * the [TileDetailsViewModel] is successfully handled. 55 * 56 * @see activeTileDetails 57 */ 58 fun onTileClicked(spec: TileSpec?): Boolean { 59 if (!shadeModeInteractor.isDualShade){ 60 return false 61 } 62 63 if (spec == null) { 64 _activeTileDetails.value = null 65 return false 66 } 67 68 val currentTile = 69 currentTilesInteractor.currentQSTiles.firstOrNull { it.tileSpec == spec.spec } 70 71 return currentTile?.getDetailsViewModel { detailsViewModel -> 72 _activeTileDetails.value = detailsViewModel 73 } ?: false 74 } 75 } 76