/* * Copyright (C) 2025 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.qs.tiles.dialog import android.content.Intent import android.provider.Settings import com.android.systemui.lifecycle.ExclusiveActivatable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import com.android.systemui.plugins.qs.TileDetailsViewModel import com.android.systemui.qs.tiles.base.domain.actions.QSTileIntentUserInputHandler import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch class AudioDetailsViewModel @AssistedInject constructor( private val qsTileIntentUserActionHandler: QSTileIntentUserInputHandler, private val volumePanelViewModelFactory: VolumePanelViewModel.Factory, ) : TileDetailsViewModel, ExclusiveActivatable() { // Controls the current content that should be displayed var contentViewModel: ContentViewModel? by mutableStateOf(null) sealed interface ContentViewModel { class DefaultPageViewModel(val viewModel: VolumePanelViewModel) : ContentViewModel class SwitcherPageViewModel : ContentViewModel } override val title: String get() = "Volume" override val subTitle: String get() = "" override fun clickOnSettingsButton() { qsTileIntentUserActionHandler.handle( /* expandable= */ null, Intent(Settings.ACTION_SOUND_SETTINGS), ) } override suspend fun onActivated(): Nothing { coroutineScope { launch { contentViewModel = ContentViewModel.DefaultPageViewModel(volumePanelViewModelFactory.create(this)) } } awaitCancellation() } @AssistedFactory fun interface Factory { fun create(): AudioDetailsViewModel } }