1 /*
2 * Copyright (C) 2022 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.settingslib.spa.widget.preference
18
19 import androidx.compose.material.icons.Icons
20 import androidx.compose.material.icons.outlined.BatteryChargingFull
21 import androidx.compose.material3.Icon
22 import androidx.compose.runtime.Composable
23 import androidx.compose.ui.Modifier
24 import androidx.compose.ui.tooling.preview.Preview
25 import androidx.compose.ui.unit.Dp
26 import com.android.settingslib.spa.framework.theme.SettingsDimension
27 import com.android.settingslib.spa.framework.theme.SettingsTheme
28 import com.android.settingslib.spa.widget.ui.SettingsBody
29
30 @Composable
BasePreferencenull31 internal fun BasePreference(
32 title: String,
33 summary: () -> String,
34 modifier: Modifier = Modifier,
35 titleContentDescription: String? = null,
36 summaryContentDescription: () -> String? = { null },
37 singleLineSummary: Boolean = false,
38 icon: @Composable (() -> Unit)? = null,
<lambda>null39 enabled: () -> Boolean = { true },
40 paddingStart: Dp = SettingsDimension.itemPaddingStart,
41 paddingEnd: Dp = SettingsDimension.itemPaddingEnd,
42 paddingVertical: Dp = SettingsDimension.itemPaddingVertical,
<lambda>null43 widget: @Composable () -> Unit = {},
44 ) {
45 BaseLayout(
46 title = title,
47 titleContentDescription = titleContentDescription,
<lambda>null48 subTitle = {
49 SettingsBody(
50 body = summary(),
51 contentDescription = summaryContentDescription(),
52 maxLines = if (singleLineSummary) 1 else Int.MAX_VALUE,
53 )
54 },
55 modifier = modifier,
56 icon = icon,
57 enabled = enabled,
58 paddingStart = paddingStart,
59 paddingEnd = paddingEnd,
60 paddingVertical = paddingVertical,
61 widget = widget,
62 )
63 }
64
65 @Preview
66 @Composable
BasePreferencePreviewnull67 private fun BasePreferencePreview() {
68 SettingsTheme {
69 BasePreference(
70 title = "Screen Saver",
71 summary = { "Clock" },
72 )
73 }
74 }
75
76 @Preview
77 @Composable
BasePreferenceIconPreviewnull78 private fun BasePreferenceIconPreview() {
79 SettingsTheme {
80 BasePreference(
81 title = "Screen Saver",
82 summary = { "Clock" },
83 icon = {
84 Icon(imageVector = Icons.Outlined.BatteryChargingFull, contentDescription = null)
85 },
86 )
87 }
88 }
89