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

Commit 85cdf614 authored by Chaohui Wang's avatar Chaohui Wang
Browse files

Add some padding between checkbox and text

On SettingsExposedDropdownMenuCheckBox.

Bug: 298906796
Test: manual - with Gallery
Test: manual - with Settings
Change-Id: I7c1690b42c79a621a759d416527930451e98643a
parent b416a714
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