Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2249f626 authored by Charlotte Lu's avatar Charlotte Lu
Browse files

Add SettingsExposedDropdownMenuCheckBox.

SettingsExposedDropdownMenuCheckBox requires input index.

Bug: 298906796
Test: Munual
Change-Id: I6059bd5371a2472fbbb9a6b0aa83be769f90264e
parent ef5e3b1a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ object SettingsExposedDropdownMenuCheckBoxProvider : SettingsPageProvider {
    override val name = "SettingsExposedDropdownMenuCheckBox"
    private const val exposedDropdownMenuCheckBoxLabel = "ExposedDropdownMenuCheckBoxLabel"
    private val options = listOf("item1", "item2", "item3")
    private val selectedOptionsState1 = mutableStateListOf("item1", "item2")
    private val selectedOptionsState1 = mutableStateListOf(0, 1)

    override fun getTitle(arguments: Bundle?): String {
        return TITLE
+10 −8
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ import com.android.settingslib.spa.framework.theme.SettingsTheme
fun SettingsExposedDropdownMenuCheckBox(
    label: String,
    options: List<String>,
    selectedOptionsState: SnapshotStateList<String>,
    selectedOptionsState: SnapshotStateList<Int>,
    emptyVal: String = "",
    enabled: Boolean,
    onSelectedOptionStateChange: () -> Unit,
) {
@@ -70,7 +71,8 @@ fun SettingsExposedDropdownMenuCheckBox(
            modifier = Modifier
                .menuAnchor()
                .fillMaxWidth(),
            value = selectedOptionsState.joinToString(", "),
            value = if (selectedOptionsState.size == 0) emptyVal
                    else selectedOptionsState.joinToString { options[it] },
            onValueChange = {},
            label = { Text(text = label) },
            trailingIcon = {
@@ -89,19 +91,19 @@ fun SettingsExposedDropdownMenuCheckBox(
                    .width(with(LocalDensity.current) { dropDownWidth.toDp() }),
                onDismissRequest = { expanded = false },
            ) {
                options.forEach { option ->
                options.forEachIndexed { index, option ->
                    TextButton(
                        modifier = Modifier
                            .fillMaxHeight()
                            .fillMaxWidth(),
                        onClick = {
                            if (selectedOptionsState.contains(option)) {
                            if (selectedOptionsState.contains(index)) {
                                selectedOptionsState.remove(
                                    option
                                    index
                                )
                            } else {
                                selectedOptionsState.add(
                                    option
                                    index
                                )
                            }
                            onSelectedOptionStateChange()
@@ -114,7 +116,7 @@ fun SettingsExposedDropdownMenuCheckBox(
                            verticalAlignment = Alignment.CenterVertically
                        ) {
                            Checkbox(
                                checked = selectedOptionsState.contains(option),
                                checked = selectedOptionsState.contains(index),
                                onCheckedChange = null,
                            )
                            Text(text = option)
@@ -130,7 +132,7 @@ fun SettingsExposedDropdownMenuCheckBox(
@Composable
private fun ActionButtonsPreview() {
    val options = listOf("item1", "item2", "item3")
    val selectedOptionsState = remember { mutableStateListOf("item1", "item2") }
    val selectedOptionsState = remember { mutableStateListOf(0, 1) }
    SettingsTheme {
        SettingsExposedDropdownMenuCheckBox(
            label = "label",
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class SettingsExposedDropdownMenuCheckBoxTest {
    private val item2 = "item2"
    private val item3 = "item3"
    private val options = listOf(item1, item2, item3)
    private val selectedOptionsState1 = mutableStateListOf(item1, item2)
    private val selectedOptionsState1 = mutableStateListOf(0, 1)
    private val exposedDropdownMenuCheckBoxLabel = "ExposedDropdownMenuCheckBoxLabel"

    @Test