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

Commit 620e26b4 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Add some padding between checkbox and text" into main

parents a84693ee 85cdf614
Loading
Loading
Loading
Loading
+46 −43
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.settingslib.spa.widget.editor

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
@@ -95,41 +94,49 @@ fun SettingsExposedDropdownMenuCheckBox(
        if (options.isNotEmpty()) {
            ExposedDropdownMenu(
                expanded = expanded,
                modifier = Modifier
                    .fillMaxWidth()
                    .width(with(LocalDensity.current) { dropDownWidth.toDp() }),
                modifier = Modifier.width(with(LocalDensity.current) { dropDownWidth.toDp() }),
                onDismissRequest = { expanded = false },
            ) {
                options.forEachIndexed { index, option ->
                    CheckboxItem(
                        selectedOptionsState,
                        index,
                        allIndex,
                        onSelectedOptionStateChange,
                        option,
                    )
                }
            }
        }
    }
}

@Composable
private fun CheckboxItem(
    selectedOptionsState: SnapshotStateList<Int>,
    index: Int,
    allIndex: Int,
    onSelectedOptionStateChange: () -> Unit,
    option: String
) {
    TextButton(
                        modifier = Modifier
                            .fillMaxHeight()
                            .fillMaxWidth(),
        modifier = Modifier.fillMaxWidth(),
        onClick = {
            if (selectedOptionsState.contains(index)) {
                                if (index == allIndex)
                if (index == allIndex) {
                    selectedOptionsState.clear()
                                else {
                                    selectedOptionsState.remove(
                                        index
                                    )
                                    if (selectedOptionsState.contains(allIndex))
                                        selectedOptionsState.remove(
                                            allIndex
                                        )
                } else {
                    selectedOptionsState.remove(index)
                    selectedOptionsState.remove(allIndex)
                }
            } else {
                                selectedOptionsState.add(
                                    index
                                )
                selectedOptionsState.add(index)
            }
            onSelectedOptionStateChange()
        }) {
        Row(
                            modifier = Modifier
                                .fillMaxHeight()
                                .fillMaxWidth(),
                            horizontalArrangement = Arrangement.Start,
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.spacedBy(SettingsDimension.itemPaddingAround),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Checkbox(
@@ -140,10 +147,6 @@ fun SettingsExposedDropdownMenuCheckBox(
        }
    }
}
            }
        }
    }
}

@Preview
@Composable