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.avatarpicker.ui
18 
19 import com.android.avatarpicker.domain.applyReadBackOrder
20 import androidx.compose.foundation.layout.Arrangement
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.foundation.layout.PaddingValues
23 import androidx.compose.foundation.layout.Row
24 import androidx.compose.foundation.layout.fillMaxHeight
25 import androidx.compose.foundation.layout.padding
26 import androidx.compose.foundation.layout.statusBarsPadding
27 import androidx.compose.foundation.lazy.grid.GridCells
28 import androidx.compose.foundation.lazy.grid.GridItemSpan
29 import androidx.compose.foundation.lazy.grid.LazyGridScope
30 import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
31 import androidx.compose.material.Divider
32 import androidx.compose.material3.BottomAppBar
33 import androidx.compose.material3.ExperimentalMaterial3Api
34 import androidx.compose.material3.MaterialTheme
35 import androidx.compose.material3.Scaffold
36 import androidx.compose.runtime.Composable
37 import androidx.compose.ui.Modifier
38 import androidx.compose.ui.unit.dp
39 
40 @ExperimentalMaterial3Api
41 @Composable
42 fun AdaptivePane(
43     showOnePane: Boolean,
44     startPane: @Composable () -> Unit,
45     endPane: (scope: LazyGridScope) -> Unit,
46     bottom: @Composable () -> Unit
47 ) {
48     Scaffold(
49         containerColor = MaterialTheme.colorScheme.surfaceContainer,
50         bottomBar = {
51             if (showOnePane) {
52                 BottomAppBar(containerColor = MaterialTheme.colorScheme.surfaceContainer) {
53                     bottom()
54                 }
55             } else {
56                 Column(modifier = Modifier.padding(start = 24.dp, end = 24.dp)) {
57                     BottomAppBar(containerColor = MaterialTheme.colorScheme.surfaceContainer) {
58                         bottom()
59                     }
60                 }
61             }
62         }) { innerPadding ->
63         Column(
64             modifier = Modifier.statusBarsPadding().padding(innerPadding)
65         ) {
66             if (showOnePane) {
67                 LazyVerticalGrid(
68                     modifier = Modifier.padding(start = 24.dp, end = 24.dp, top = 8.dp),
69                     columns = GridCells.Fixed(4),
70                     horizontalArrangement = Arrangement.spacedBy(24.dp),
71                     verticalArrangement = Arrangement.spacedBy(24.dp),
72                     contentPadding = PaddingValues(bottom = 24.dp)
73                 ) {
74                     item(span = { GridItemSpan(maxLineSpan) }) {
75                         Column {
76                             startPane()
77                         }
78                     }
79                     endPane(this)
80                 }
81             } else {
82                 Row(
83                     modifier = Modifier.statusBarsPadding()
84                         .padding(start = 24.dp, end = 24.dp, top = 24.dp),
85                     horizontalArrangement = Arrangement.spacedBy(24.dp)
86                 ) {
87                     Column(modifier = Modifier.weight(1f)
88                         .padding(start = 24.dp, end = 24.dp, top = 8.dp)
89                         .applyReadBackOrder()) { startPane() }
90 
91                     LazyVerticalGrid(
92                         modifier = Modifier.weight(1f)
93                             .padding(top = 104.dp, start = 24.dp, end = 24.dp)
94                             .fillMaxHeight(),
95                         columns = GridCells.Fixed(4),
96                         horizontalArrangement = Arrangement.spacedBy(24.dp),
97                         verticalArrangement = Arrangement.spacedBy(24.dp),
98                         contentPadding = PaddingValues(bottom = 24.dp),
99                     ) {
100                         endPane(this)
101                     }
102 
103                 }
104                 Divider(color = MaterialTheme.colorScheme.primary, thickness = 1.dp)
105             }
106         }
107     }
108 }