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.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row 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.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.material3.DropdownMenu 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 */ /** Icon if resource is a vector image, (bitmap) Image otherwise */
@Composable @Composable
fun IconOrImage(@DrawableRes resId: Int, name: String?, sizeDp: Float) { 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.Surface
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState 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.getStringResourceOrName
import helium314.keyboard.latin.utils.mainLayoutName import helium314.keyboard.latin.utils.mainLayoutName
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
import helium314.keyboard.settings.ActionRow
import helium314.keyboard.settings.DefaultButton import helium314.keyboard.settings.DefaultButton
import helium314.keyboard.settings.DeleteButton import helium314.keyboard.settings.DeleteButton
import helium314.keyboard.settings.DropDownField import helium314.keyboard.settings.DropDownField
@ -156,28 +156,39 @@ fun SubtypeScreen(
MainLayoutRow(currentSubtype, customMainLayouts) { setCurrentSubtype(it) } MainLayoutRow(currentSubtype, customMainLayouts) { setCurrentSubtype(it) }
if (availableLocalesForScript.size > 1) { if (availableLocalesForScript.size > 1) {
WithSmallTitle(stringResource(R.string.secondary_locale)) { WithSmallTitle(stringResource(R.string.secondary_locale)) {
TextButton(onClick = { showSecondaryLocaleDialog = true }) { ActionRow(onClick = { showSecondaryLocaleDialog = true }) {
val text = getSecondaryLocales(currentSubtype.extraValues).joinToString(", ") { val text = getSecondaryLocales(currentSubtype.extraValues).joinToString(", ") {
it.localizedDisplayName(ctx.resources) it.localizedDisplayName(ctx.resources)
}.ifEmpty { stringResource(R.string.action_none) } }.ifEmpty { stringResource(R.string.action_none) }
Text(text, Modifier.fillMaxWidth()) Text(text, modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
} }
} }
} }
Row { WithSmallTitle(stringResource(R.string.popup_order_and_hint_source)) {
TextButton(onClick = { showKeyOrderDialog = true }, Modifier.weight(1f)) ActionRow(onClick = { showKeyOrderDialog = true }) {
{ Text(stringResource(R.string.popup_order)) } Text(stringResource(R.string.popup_order),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.POPUP_ORDER) == null) { DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.POPUP_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.POPUP_ORDER)) setCurrentSubtype(currentSubtype.without(ExtraValue.POPUP_ORDER))
} }
} }
Row { ActionRow(onClick = { showHintOrderDialog = true }) {
TextButton(onClick = { showHintOrderDialog = true }, Modifier.weight(1f)) Text(stringResource(R.string.hint_source),
{ Text(stringResource(R.string.hint_source)) } modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.HINT_ORDER) == null) { DefaultButton(currentSubtype.getExtraValueOf(ExtraValue.HINT_ORDER) == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.HINT_ORDER)) setCurrentSubtype(currentSubtype.without(ExtraValue.HINT_ORDER))
} }
} }
}
if (currentSubtype.locale.script() == ScriptUtils.SCRIPT_LATIN) { if (currentSubtype.locale.script() == ScriptUtils.SCRIPT_LATIN) {
WithSmallTitle(stringResource(R.string.show_popup_keys_title)) { WithSmallTitle(stringResource(R.string.show_popup_keys_title)) {
val explicitValue = currentSubtype.getExtraValueOf(ExtraValue.MORE_POPUPS) val explicitValue = currentSubtype.getExtraValueOf(ExtraValue.MORE_POPUPS)
@ -185,9 +196,12 @@ fun SubtypeScreen(
Settings.PREF_MORE_POPUP_KEYS, Settings.PREF_MORE_POPUP_KEYS,
Defaults.PREF_MORE_POPUP_KEYS Defaults.PREF_MORE_POPUP_KEYS
)!! )!!
Row { ActionRow(onClick = { showMorePopupsDialog = true }) {
TextButton(onClick = { showMorePopupsDialog = true }, Modifier.weight(1f)) Text(stringResource(morePopupKeysResId(value)),
{ Text(stringResource(morePopupKeysResId(value))) } modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
DefaultButton(explicitValue == null) { DefaultButton(explicitValue == null) {
setCurrentSubtype(currentSubtype.without(ExtraValue.MORE_POPUPS)) setCurrentSubtype(currentSubtype.without(ExtraValue.MORE_POPUPS))
} }
@ -195,9 +209,14 @@ fun SubtypeScreen(
} }
} }
if (hasLocalizedNumberRow(currentSubtype.locale, ctx)) { if (hasLocalizedNumberRow(currentSubtype.locale, ctx)) {
Row(verticalAlignment = Alignment.CenterVertically) {
val checked = currentSubtype.getExtraValueOf(ExtraValue.LOCALIZED_NUMBER_ROW)?.toBoolean() val checked = currentSubtype.getExtraValueOf(ExtraValue.LOCALIZED_NUMBER_ROW)?.toBoolean()
Text(stringResource(R.string.localized_number_row), Modifier.weight(1f)) WithSmallTitle(stringResource(R.string.number_row)) {
ActionRow {
Text(stringResource(R.string.localized_number_row),
modifier = Modifier
.weight(1f)
.padding(start = 10.dp)
)
Switch( Switch(
checked = checked ?: prefs.getBoolean( checked = checked ?: prefs.getBoolean(
Settings.PREF_LOCALIZED_NUMBER_ROW, Settings.PREF_LOCALIZED_NUMBER_ROW,
@ -212,6 +231,7 @@ fun SubtypeScreen(
} }
} }
} }
}
HorizontalDivider() HorizontalDivider()
Text( Text(
stringResource(R.string.settings_screen_secondary_layouts), stringResource(R.string.settings_screen_secondary_layouts),

View file

@ -270,6 +270,8 @@
<string name="show_hints">Show key hints</string> <string name="show_hints">Show key hints</string>
<!-- Description of the settings to show hints --> <!-- Description of the settings to show hints -->
<string name="show_hints_summary">Show long-press hints</string> <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 --> <!-- Title of the setting to select key hints source -->
<string name="hint_source">Select hint source</string> <string name="hint_source">Select hint source</string>
<!-- Title of the setting to set popup key order --> <!-- Title of the setting to set popup key order -->