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.volume.panel.component.volume.ui.composable 18 19 import androidx.compose.foundation.layout.fillMaxWidth 20 import androidx.compose.runtime.Composable 21 import androidx.compose.runtime.getValue 22 import androidx.compose.ui.Modifier 23 import androidx.lifecycle.compose.collectAsStateWithLifecycle 24 import com.android.compose.PlatformSliderDefaults 25 import com.android.systemui.volume.panel.component.volume.slider.ui.viewmodel.SliderViewModel 26 import com.android.systemui.volume.panel.component.volume.ui.viewmodel.AudioVolumeComponentViewModel 27 import com.android.systemui.volume.panel.component.volume.ui.viewmodel.SlidersExpandableViewModel 28 import com.android.systemui.volume.panel.ui.composable.ComposeVolumePanelUiComponent 29 import com.android.systemui.volume.panel.ui.composable.VolumePanelComposeScope 30 import com.android.systemui.volume.panel.ui.composable.isPortrait 31 import javax.inject.Inject 32 33 class VolumeSlidersComponent 34 @Inject 35 constructor( 36 private val viewModel: AudioVolumeComponentViewModel, 37 ) : ComposeVolumePanelUiComponent { 38 39 @Composable Contentnull40 override fun VolumePanelComposeScope.Content(modifier: Modifier) { 41 val sliderViewModels: List<SliderViewModel> by 42 viewModel.sliderViewModels.collectAsStateWithLifecycle() 43 if (sliderViewModels.isEmpty()) { 44 return 45 } 46 if (isLargeScreen) { 47 GridVolumeSliders( 48 viewModels = sliderViewModels, 49 sliderColors = PlatformSliderDefaults.defaultPlatformSliderColors(), 50 modifier = modifier.fillMaxWidth(), 51 ) 52 } else { 53 val expandableViewModel: SlidersExpandableViewModel by 54 viewModel 55 .isExpandable(isPortrait) 56 .collectAsStateWithLifecycle(SlidersExpandableViewModel.Unavailable) 57 if (expandableViewModel is SlidersExpandableViewModel.Unavailable) { 58 return 59 } 60 val isExpanded = 61 (expandableViewModel as? SlidersExpandableViewModel.Expandable)?.isExpanded ?: true 62 ColumnVolumeSliders( 63 viewModels = sliderViewModels, 64 isExpanded = isExpanded, 65 onExpandedChanged = viewModel::onExpandedChanged, 66 sliderColors = PlatformSliderDefaults.defaultPlatformSliderColors(), 67 isExpandable = expandableViewModel is SlidersExpandableViewModel.Expandable, 68 modifier = modifier.fillMaxWidth(), 69 ) 70 } 71 } 72 } 73