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.animation.AnimatedContent
20 import androidx.compose.animation.AnimatedVisibility
21 import androidx.compose.foundation.layout.Arrangement
22 import androidx.compose.foundation.layout.Column
23 import androidx.compose.foundation.layout.Row
24 import androidx.compose.foundation.layout.Spacer
25 import androidx.compose.foundation.layout.fillMaxWidth
26 import androidx.compose.foundation.layout.wrapContentHeight
27 import androidx.compose.foundation.rememberScrollState
28 import androidx.compose.foundation.verticalScroll
29 import androidx.compose.runtime.Composable
30 import androidx.compose.ui.Modifier
31 import androidx.compose.ui.unit.dp
32 import androidx.compose.ui.util.fastSumBy
33 import com.android.systemui.volume.panel.ui.layout.ComponentsLayout
34 
35 @Composable
36 fun VolumePanelComposeScope.VerticalVolumePanelContent(
37     layout: ComponentsLayout,
38     modifier: Modifier = Modifier,
39 ) {
40     Column(
41         modifier = modifier.verticalScroll(rememberScrollState()),
42         verticalArrangement = Arrangement.spacedBy(20.dp),
43     ) {
44         for (component in layout.headerComponents) {
45             AnimatedVisibility(component.isVisible) {
46                 with(component.component as ComposeVolumePanelUiComponent) { Content(Modifier) }
47             }
48         }
49         for (component in layout.contentComponents) {
50             AnimatedVisibility(component.isVisible) {
51                 with(component.component as ComposeVolumePanelUiComponent) { Content(Modifier) }
52             }
53         }
54 
55         AnimatedContent(
56             targetState = layout.footerComponents,
57             label = "FooterComponentAnimation",
58         ) { footerComponents ->
59             Row(
60                 modifier = Modifier.fillMaxWidth().wrapContentHeight(),
61                 horizontalArrangement = Arrangement.spacedBy(if (isLargeScreen) 28.dp else 20.dp),
62             ) {
63                 val visibleComponentsCount =
64                     footerComponents.fastSumBy { if (it.isVisible) 1 else 0 }
65 
66                 // Center footer component if there is only one present
67                 if (visibleComponentsCount == 1) {
68                     Spacer(modifier = Modifier.weight(0.5f))
69                 }
70 
71                 for (component in footerComponents) {
72                     if (component.isVisible) {
73                         with(component.component as ComposeVolumePanelUiComponent) {
74                             Content(Modifier.weight(1f))
75                         }
76                     }
77                 }
78 
79                 if (visibleComponentsCount == 1) {
80                     Spacer(modifier = Modifier.weight(0.5f))
81                 }
82             }
83         }
84     }
85 }
86