1 /*
<lambda>null2 * Copyright (C) 2023 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.ui.composable
18
19 import androidx.compose.foundation.layout.Arrangement
20 import androidx.compose.foundation.layout.Box
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.foundation.layout.fillMaxWidth
23 import androidx.compose.foundation.layout.heightIn
24 import androidx.compose.foundation.layout.padding
25 import androidx.compose.runtime.Composable
26 import androidx.compose.runtime.getValue
27 import androidx.compose.ui.Alignment
28 import androidx.compose.ui.Modifier
29 import androidx.compose.ui.res.stringResource
30 import androidx.compose.ui.semantics.paneTitle
31 import androidx.compose.ui.semantics.semantics
32 import androidx.compose.ui.unit.dp
33 import androidx.lifecycle.compose.collectAsStateWithLifecycle
34 import com.android.systemui.res.R
35 import com.android.systemui.volume.panel.ui.layout.ComponentsLayout
36 import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelState
37 import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
38
39 private val padding = 24.dp
40
41 @Composable
42 fun VolumePanelRoot(
43 viewModel: VolumePanelViewModel,
44 modifier: Modifier = Modifier,
45 ) {
46 val accessibilityTitle = stringResource(R.string.accessibility_volume_settings)
47 val state: VolumePanelState by viewModel.volumePanelState.collectAsStateWithLifecycle()
48 val components by viewModel.componentsLayout.collectAsStateWithLifecycle(null)
49
50 with(VolumePanelComposeScope(state)) {
51 components?.let { componentsState ->
52 Components(
53 componentsState,
54 modifier
55 .semantics { paneTitle = accessibilityTitle }
56 .padding(
57 start = padding,
58 top = padding,
59 end = padding,
60 bottom = 20.dp,
61 )
62 )
63 }
64 }
65 }
66
67 @Composable
Componentsnull68 private fun VolumePanelComposeScope.Components(
69 layout: ComponentsLayout,
70 modifier: Modifier = Modifier
71 ) {
72 val arrangement: Arrangement.Vertical =
73 if (isLargeScreen) {
74 Arrangement.spacedBy(20.dp)
75 } else {
76 if (isPortrait) Arrangement.spacedBy(padding) else Arrangement.spacedBy(4.dp)
77 }
78 Column(
79 modifier = modifier,
80 verticalArrangement = arrangement,
81 ) {
82 if (isPortrait || isLargeScreen) {
83 VerticalVolumePanelContent(
84 modifier = Modifier.weight(weight = 1f, fill = false),
85 layout = layout
86 )
87 } else {
88 HorizontalVolumePanelContent(
89 modifier = Modifier.weight(weight = 1f, fill = false).heightIn(max = 212.dp),
90 layout = layout,
91 )
92 }
93 BottomBar(
94 modifier = Modifier,
95 layout = layout,
96 )
97 }
98 }
99
100 @Composable
VolumePanelComposeScopenull101 private fun VolumePanelComposeScope.BottomBar(
102 layout: ComponentsLayout,
103 modifier: Modifier = Modifier
104 ) {
105 if (layout.bottomBarComponent.isVisible) {
106 Box(
107 modifier = modifier.fillMaxWidth(),
108 contentAlignment = Alignment.Center,
109 ) {
110 with(layout.bottomBarComponent.component as ComposeVolumePanelUiComponent) {
111 Content(Modifier)
112 }
113 }
114 }
115 }
116