Fix unnecessary indentations in the Subtype screen (#1516) (#1648)

This commit is contained in:
BlackyHawky 2025-06-02 17:12:11 +02:00 committed by GitHub
parent d0787201ae
commit 20d4704090
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 74 additions and 30 deletions

View file

@ -8,6 +8,9 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.DropdownMenu
@ -43,6 +46,25 @@ fun WithSmallTitle(
}
}
@Composable
fun ActionRow(
modifier: Modifier = Modifier,
onClick: (() -> Unit)? = null,
verticalAlignment: Alignment.Vertical = Alignment.CenterVertically,
content: @Composable RowScope.() -> Unit
) {
val clickableModifier = if (onClick != null) Modifier.clickable(onClick = onClick)
else Modifier
Row(
modifier = modifier
.then(clickableModifier)
.fillMaxWidth()
.heightIn(min = 44.dp),
verticalAlignment = verticalAlignment,
content = content
)
}
/** Icon if resource is a vector image, (bitmap) Image otherwise */
@Composable
fun IconOrImage(@DrawableRes resId: Int, name: String?, sizeDp: Float) {

View file

@ -21,7 +21,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
@ -73,6 +72,7 @@ import helium314.keyboard.latin.utils.getSecondaryLocales
import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.mainLayoutName
import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.ActionRow
import helium314.keyboard.settings.DefaultButton
import helium314.keyboard.settings.DeleteButton
import helium314.keyboard.settings.DropDownField
@ -156,26 +156,37 @@ fun SubtypeScreen(
MainLayoutRow(currentSubtype, customMainLayouts) { setCurrentSubtype(it) }
if (availableLocalesForScript.size > 1) {
WithSmallTitle(stringResource(R.string.secondary_locale)) {
TextButton(onClick = { showSecondaryLocaleDialog = true }) {
ActionRow(onClick = { showSecondaryLocaleDialog = true }) {
val text = getSecondaryLocales(currentSubtype.extraValues).joinToString(", ") {
it.localizedDisplayName(ctx.resources)
}.ifEmpty { stringResource(R.string.action_none) }
Text(text, Modifier.fillMaxWidth())
Text(text, modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
}
}
}
Row {
TextButton(onClick = { showKeyOrderDialog = true }, Modifier.weight(1f))
{ Text(stringResource(R.string.popup_order)) }
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.POPUP_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.POPUP_ORDER))
WithSmallTitle(stringResource(R.string.popup_order_and_hint_source)) {
ActionRow(onClick = { showKeyOrderDialog = true }) {
Text(stringResource(R.string.popup_order),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.POPUP_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.POPUP_ORDER))
}
}
}
Row {
TextButton(onClick = { showHintOrderDialog = true }, Modifier.weight(1f))
{ Text(stringResource(R.string.hint_source)) }
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.HINT_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.HINT_ORDER))
ActionRow(onClick = { showHintOrderDialog = true }) {
Text(stringResource(R.string.hint_source),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.HINT_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.HINT_ORDER))
}
}
}
if (currentSubtype.locale.script() == ScriptUtils.SCRIPT_LATIN) {
@ -185,9 +196,12 @@ fun SubtypeScreen(
Settings.PREF_MORE_POPUP_KEYS,
Defaults.PREF_MORE_POPUP_KEYS
)!!
Row {
TextButton(onClick = { showMorePopupsDialog = true }, Modifier.weight(1f))
{ Text(stringResource(morePopupKeysResId(value))) }
ActionRow(onClick = { showMorePopupsDialog = true }) {
Text(stringResource(morePopupKeysResId(value)),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(explicitValue == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.MORE_POPUPS))
}
@ -195,20 +209,26 @@ fun SubtypeScreen(
}
}
if (hasLocalizedNumberRow(currentSubtype.locale, ctx)) {
Row(verticalAlignment = Alignment.CenterVertically) {
val checked = currentSubtype.getExtraValueOf(ExtraValue.LOCALIZED_NUMBER_ROW)?.toBoolean()
Text(stringResource(R.string.localized_number_row), Modifier.weight(1f))
Switch(
checked = checked ?: prefs.getBoolean(
Settings.PREF_LOCALIZED_NUMBER_ROW,
Defaults.PREF_LOCALIZED_NUMBER_ROW
),
onCheckedChange = {
setCurrentSubtype(currentSubtype.with(ExtraValue.LOCALIZED_NUMBER_ROW, it.toString()))
val checked = currentSubtype.getExtraValueOf(ExtraValue.LOCALIZED_NUMBER_ROW)?.toBoolean()
WithSmallTitle(stringResource(R.string.number_row)) {
ActionRow {
Text(stringResource(R.string.localized_number_row),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
Switch(
checked = checked ?: prefs.getBoolean(
Settings.PREF_LOCALIZED_NUMBER_ROW,
Defaults.PREF_LOCALIZED_NUMBER_ROW
),
onCheckedChange = {
setCurrentSubtype(currentSubtype.with(ExtraValue.LOCALIZED_NUMBER_ROW, it.toString()))
}
)
DefaultButton(checked == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.LOCALIZED_NUMBER_ROW))
}
)
DefaultButton(checked == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.LOCALIZED_NUMBER_ROW))
}
}
}

View file

@ -270,6 +270,8 @@
<string name="show_hints">Show key hints</string>
<!-- Description of the settings to show hints -->
<string name="show_hints_summary">Show long-press hints</string>
<!-- Preferences item to set popup key order and select hints source -->
<string name="popup_order_and_hint_source">Popup key order and hints source</string>
<!-- Title of the setting to select key hints source -->
<string name="hint_source">Select hint source</string>
<!-- Title of the setting to set popup key order -->