slightly adjust behavior and layouts of subtype screen

This commit is contained in:
Helium314 2025-03-31 01:27:06 +02:00
parent 6bbce0b5ca
commit 3dbd9c6ed9

View file

@ -1,12 +1,12 @@
package helium314.keyboard.settings.screens package helium314.keyboard.settings.screens
import android.content.Context import android.content.Context
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
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.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
@ -61,6 +61,7 @@ import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings import helium314.keyboard.latin.utils.SubtypeSettings
import helium314.keyboard.latin.utils.SubtypeUtilsAdditional import helium314.keyboard.latin.utils.SubtypeUtilsAdditional
import helium314.keyboard.latin.utils.appendLink import helium314.keyboard.latin.utils.appendLink
import helium314.keyboard.latin.utils.displayName
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getDictionaryLocales import helium314.keyboard.latin.utils.getDictionaryLocales
import helium314.keyboard.latin.utils.getSecondaryLocales import helium314.keyboard.latin.utils.getSecondaryLocales
@ -85,11 +86,6 @@ import helium314.keyboard.settings.layoutIntent
import helium314.keyboard.settings.previewDark import helium314.keyboard.settings.previewDark
import java.util.Locale import java.util.Locale
// todo:
// dropdowns are weird
// at very least too wide and too high
// also too wide left (anchor should be icon)
// title shows only the layout name
@Composable @Composable
fun SubtypeScreen( fun SubtypeScreen(
initialSubtype: SettingsSubtype, initialSubtype: SettingsSubtype,
@ -140,10 +136,7 @@ fun SubtypeScreen(
SubtypeSettings.removeEnabledSubtype(ctx, currentSubtype.toAdditionalSubtype()) SubtypeSettings.removeEnabledSubtype(ctx, currentSubtype.toAdditionalSubtype())
onClickBack() onClickBack()
} }, } },
title = { title = { Text(currentSubtype.toAdditionalSubtype().displayName(ctx)) },
val mainLayout = currentSubtype.mainLayoutName() ?: SubtypeLocaleUtils.QWERTY
Text(SubtypeLocaleUtils.getDisplayNameInSystemLocale(mainLayout, currentSubtype.locale))
},
itemContent = { }, itemContent = { },
filteredItems = { emptyList<String>() } filteredItems = { emptyList<String>() }
) { ) {
@ -228,11 +221,12 @@ fun SubtypeScreen(
var showLayoutEditDialog by remember { mutableStateOf(false) } var showLayoutEditDialog by remember { mutableStateOf(false) }
Row( Row(
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
) { ) {
Text(displayName, Modifier.padding(end = 8.dp)) Text(displayName)
if (LayoutUtilsCustom.isCustomLayout(it)) if (LayoutUtilsCustom.isCustomLayout(it))
Icon(painterResource(R.drawable.ic_edit), stringResource(R.string.edit_layout), Modifier.clickable { showLayoutEditDialog = true }) IconButton({ showLayoutEditDialog = true }) { Icon(painterResource(R.drawable.ic_edit), stringResource(R.string.edit_layout)) }
} }
if (showLayoutEditDialog) if (showLayoutEditDialog)
LayoutEditDialog( LayoutEditDialog(
@ -376,18 +370,18 @@ private fun MainLayoutRow(
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth() modifier = Modifier.widthIn(min = 200.dp).fillMaxWidth()
) { ) {
Text(SubtypeLocaleUtils.getDisplayNameInSystemLocale(it, currentSubtype.locale)) Text(SubtypeLocaleUtils.getDisplayNameInSystemLocale(it, currentSubtype.locale))
Row (verticalAlignment = Alignment.CenterVertically) { Row (verticalAlignment = Alignment.CenterVertically) {
Icon(painterResource(R.drawable.ic_edit), stringResource(R.string.edit_layout), Modifier.clickable { showLayoutEditDialog = it to null }) IconButton({ showLayoutEditDialog = it to null }) { Icon(painterResource(R.drawable.ic_edit), stringResource(R.string.edit_layout)) }
if (it in customLayouts && currentSubtype.mainLayoutName() != it) // don't allow current main layout // todo: this was initialSubtype, maybe needs adjustment now if (it in customLayouts)
Icon(painterResource(R.drawable.ic_bin), stringResource(R.string.delete), Modifier.clickable { showLayoutDeleteDialog = true }) IconButton({ showLayoutDeleteDialog = true }) { Icon(painterResource(R.drawable.ic_bin), stringResource(R.string.delete)) }
} }
} }
if (showLayoutDeleteDialog) { if (showLayoutDeleteDialog) {
val others = SubtypeSettings.getAdditionalSubtypes().filter { st -> st.mainLayoutName() == it } val others = SubtypeSettings.getAdditionalSubtypes().filter { st -> st.mainLayoutName() == it }
.any { it.toSettingsSubtype() != currentSubtype } // todo: this was initialSubtype, maybe needs adjustment now .any { it.toSettingsSubtype() != currentSubtype }
ConfirmationDialog( ConfirmationDialog(
onDismissRequest = { showLayoutDeleteDialog = false }, onDismissRequest = { showLayoutDeleteDialog = false },
confirmButtonText = stringResource(R.string.delete), confirmButtonText = stringResource(R.string.delete),
@ -454,7 +448,6 @@ private fun MainLayoutRow(
private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale): List<Locale> = private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale): List<Locale> =
getDictionaryLocales(context).filter { it != mainLocale && it.script() == mainLocale.script() } getDictionaryLocales(context).filter { it != mainLocale && it.script() == mainLocale.script() }
@Preview @Preview
@Composable @Composable
private fun Preview() { private fun Preview() {