1 /*
2  * 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.permissioncontroller.permission.ui.wear.elements
18 
19 import androidx.compose.foundation.clickable
20 import androidx.compose.foundation.layout.Row
21 import androidx.compose.foundation.layout.Spacer
22 import androidx.compose.foundation.layout.fillMaxWidth
23 import androidx.compose.foundation.layout.size
24 import androidx.compose.foundation.layout.width
25 import androidx.compose.runtime.Composable
26 import androidx.compose.ui.Alignment
27 import androidx.compose.ui.Modifier
28 import androidx.compose.ui.res.painterResource
29 import androidx.compose.ui.text.style.TextAlign
30 import androidx.compose.ui.text.style.TextOverflow
31 import androidx.compose.ui.unit.dp
32 import androidx.wear.compose.material.Icon
33 import androidx.wear.compose.material.MaterialTheme
34 import androidx.wear.compose.material.Text
35 
36 /** A slot based composable for creating a list footer item. */
37 @Composable
ListFooternull38 fun ListFooter(description: String, iconRes: Int? = null, onClick: (() -> Unit)? = null) {
39     val modifier = Modifier.fillMaxWidth()
40     Row(
41         modifier =
42             if (onClick == null) {
43                 modifier
44             } else {
45                 modifier.clickable(onClick = onClick)
46             }
47     ) {
48         iconRes?.let {
49             Spacer(modifier = Modifier.width(LeadingIconStartSpacing))
50             Icon(
51                 painter = painterResource(id = it),
52                 contentDescription = null,
53                 modifier =
54                     Modifier.size(LeadingIconSize, LeadingIconSize)
55                         .align(Alignment.CenterVertically)
56             )
57             Spacer(modifier = Modifier.width(LeadingIconEndSpacing))
58         }
59         Text(
60             text = description,
61             modifier = Modifier.fillMaxWidth(),
62             textAlign = TextAlign.Start,
63             overflow = TextOverflow.Ellipsis,
64             color = MaterialTheme.colors.onSurfaceVariant,
65             style = MaterialTheme.typography.caption2
66         )
67     }
68 }
69 
70 /** The size of the spacing before the leading icon when they used inside a list footer. */
71 private val LeadingIconStartSpacing = 4.dp
72 
73 /** The size of the spacing between the leading icon and a text inside a list footer. */
74 private val LeadingIconEndSpacing = 8.dp
75 
76 /** The size of the leading icon. */
77 private val LeadingIconSize = 24.dp
78