1 /*
2 * Copyright (C) 2024 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.gallery.editor
18
19 import android.os.Bundle
20 import androidx.compose.runtime.Composable
21 import androidx.compose.runtime.mutableStateOf
22 import androidx.compose.runtime.remember
23 import androidx.compose.ui.tooling.preview.Preview
24 import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
25 import com.android.settingslib.spa.framework.common.SettingsPageProvider
26 import com.android.settingslib.spa.framework.common.createSettingsPage
27 import com.android.settingslib.spa.framework.compose.navigator
28 import com.android.settingslib.spa.framework.theme.SettingsTheme
29 import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckBox
30 import com.android.settingslib.spa.widget.editor.SettingsDropdownCheckOption
31 import com.android.settingslib.spa.widget.preference.Preference
32 import com.android.settingslib.spa.widget.preference.PreferenceModel
33 import com.android.settingslib.spa.widget.scaffold.RegularScaffold
34
35 private const val TITLE = "Sample SettingsDropdownCheckBox"
36
37 object SettingsDropdownCheckBoxProvider : SettingsPageProvider {
38 override val name = "SettingsDropdownCheckBox"
39
getTitlenull40 override fun getTitle(arguments: Bundle?): String {
41 return TITLE
42 }
43
44 @Composable
Pagenull45 override fun Page(arguments: Bundle?) {
46 RegularScaffold(title = TITLE) {
47 SettingsDropdownCheckBox(
48 label = "SettingsDropdownCheckBox",
49 options = remember {
50 listOf(
51 SettingsDropdownCheckOption("Item 1"),
52 SettingsDropdownCheckOption("Item 2"),
53 SettingsDropdownCheckOption("Item 3"),
54 )
55 },
56 )
57 SettingsDropdownCheckBox(
58 label = "Empty list",
59 options = emptyList(),
60 )
61 SettingsDropdownCheckBox(
62 label = "Disabled",
63 options = remember {
64 listOf(
65 SettingsDropdownCheckOption("Item 1", selected = mutableStateOf(true)),
66 SettingsDropdownCheckOption("Item 2"),
67 SettingsDropdownCheckOption("Item 3"),
68 )
69 },
70 enabled = false,
71 )
72 SettingsDropdownCheckBox(
73 label = "With disabled item",
74 options = remember {
75 listOf(
76 SettingsDropdownCheckOption("Enabled item 1"),
77 SettingsDropdownCheckOption("Enabled item 2"),
78 SettingsDropdownCheckOption(
79 text = "Disabled item 1",
80 changeable = false,
81 selected = mutableStateOf(true),
82 ),
83 SettingsDropdownCheckOption("Disabled item 2", changeable = false),
84 )
85 },
86 )
87 SettingsDropdownCheckBox(
88 label = "With select all",
89 options = remember {
90 listOf(
91 SettingsDropdownCheckOption("All", isSelectAll = true),
92 SettingsDropdownCheckOption("Item 1"),
93 SettingsDropdownCheckOption("Item 2"),
94 SettingsDropdownCheckOption("Item 3"),
95 )
96 },
97 )
98 SettingsDropdownCheckBox(
99 label = "With disabled item and select all",
100 options =
101 remember {
102 listOf(
103 SettingsDropdownCheckOption("All", isSelectAll = true, changeable = false),
104 SettingsDropdownCheckOption("Enabled item 1"),
105 SettingsDropdownCheckOption("Enabled item 2"),
106 SettingsDropdownCheckOption(
107 text = "Disabled item 1",
108 changeable = false,
109 selected = mutableStateOf(true),
110 ),
111 SettingsDropdownCheckOption("Disabled item 2", changeable = false),
112 )
113 },
114 )
115 }
116 }
117
buildInjectEntrynull118 fun buildInjectEntry(): SettingsEntryBuilder {
119 return SettingsEntryBuilder.createInject(owner = createSettingsPage()).setUiLayoutFn {
120 Preference(object : PreferenceModel {
121 override val title = TITLE
122 override val onClick = navigator(name)
123 })
124 }
125 }
126 }
127
128 @Preview(showBackground = true)
129 @Composable
SettingsDropdownCheckBoxPagePreviewnull130 private fun SettingsDropdownCheckBoxPagePreview() {
131 SettingsTheme {
132 SettingsDropdownCheckBoxProvider.Page(null)
133 }
134 }
135