use some resource strings again

This commit is contained in:
Helium314 2025-03-02 09:59:03 +01:00
parent cffdbff23c
commit 2fb618888b
6 changed files with 113 additions and 75 deletions

View file

@ -0,0 +1,82 @@
package helium314.keyboard.settings
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.padding
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.R
@Composable
fun WithSmallTitle(
description: String,
content: @Composable () -> Unit,
) {
Column {
Text(description, style = MaterialTheme.typography.titleSmall)
content()
}
}
@Composable
fun <T>DropDownField(
items: List<T>,
selectedItem: T,
onSelected: (T) -> Unit,
extraButton: @Composable (() -> Unit)? = null,
itemContent: @Composable (T) -> Unit,
) {
var expanded by remember { mutableStateOf(false) }
Box(
Modifier.clickable { expanded = !expanded }
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 8.dp, bottom = 4.dp)
) {
Box(Modifier.weight(1f)) {
itemContent(selectedItem)
}
IconButton(
onClick = { expanded = !expanded },
enabled = items.size > 1
) {
Icon(
painterResource(R.drawable.ic_arrow_left),
"show dropdown",
Modifier.rotate(-90f)
)
}
if (extraButton != null)
extraButton()
}
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
items.forEach {
DropdownMenuItem(
text = { itemContent(it) },
onClick = { expanded = false; onSelected(it) }
)
}
}
}

View file

@ -47,6 +47,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.utils.JniUtils
import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils import helium314.keyboard.latin.utils.UncachedInputMethodManagerUtils
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -83,12 +84,20 @@ fun WelcomeWizard(
val appName = stringResource(ctx.applicationInfo.labelRes) val appName = stringResource(ctx.applicationInfo.labelRes)
@Composable fun bigText() { @Composable fun bigText() {
val resource = if (step == 0) R.string.setup_welcome_title else R.string.setup_steps_title val resource = if (step == 0) R.string.setup_welcome_title else R.string.setup_steps_title
Column(Modifier.padding(bottom = 36.dp)) {
Text( Text(
stringResource(resource, appName), stringResource(resource, appName),
style = MaterialTheme.typography.displayMedium, style = MaterialTheme.typography.displayMedium,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
modifier = Modifier.padding(bottom = 36.dp)
) )
if (JniUtils.sHaveGestureLib)
Text(
stringResource(R.string.setup_welcome_additional_description),
style = MaterialTheme.typography.bodyLarge,
textAlign = TextAlign.End,
modifier = Modifier.fillMaxWidth()
)
}
} }
@Composable fun steps() { @Composable fun steps() {
if (step == 0) if (step == 0)

View file

@ -28,6 +28,8 @@ import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.ScriptUtils.script import helium314.keyboard.latin.utils.ScriptUtils.script
import helium314.keyboard.latin.utils.SubtypeSettings import helium314.keyboard.latin.utils.SubtypeSettings
import helium314.keyboard.latin.utils.locale import helium314.keyboard.latin.utils.locale
import helium314.keyboard.settings.DropDownField
import helium314.keyboard.settings.WithSmallTitle
import java.io.File import java.io.File
import java.util.Locale import java.util.Locale
@ -68,14 +70,18 @@ fun NewDictionaryDialog(
val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION) val newDictBroadcast = Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION)
ctx.sendBroadcast(newDictBroadcast) ctx.sendBroadcast(newDictBroadcast)
}, },
confirmButtonText = stringResource(if (dictFile.exists()) R.string.replace_dictionary else android.R.string.ok),
title = { Text(stringResource(R.string.add_new_dictionary_title)) },
content = { content = {
Column { Column {
Text(info) Text(info, Modifier.padding(bottom = 10.dp))
WithSmallTitle(stringResource(R.string.button_select_language)) {
DropDownField( DropDownField(
selectedItem = locale, selectedItem = locale,
onSelected = { locale = it }, onSelected = { locale = it },
items = locales items = locales
) { Text(it.localizedDisplayName(ctx)) } ) { Text(it.localizedDisplayName(ctx)) }
}
if (locale.script() != dictLocale.script()) { if (locale.script() != dictLocale.script()) {
// whatever, still allow it if the user wants // whatever, still allow it if the user wants
HorizontalDivider() HorizontalDivider()

View file

@ -4,15 +4,12 @@ package helium314.keyboard.settings.dialogs
import android.content.Context import android.content.Context
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
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.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
@ -30,7 +27,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
@ -72,8 +68,10 @@ 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.DefaultButton import helium314.keyboard.settings.DefaultButton
import helium314.keyboard.settings.DropDownField
import helium314.keyboard.settings.SettingsActivity import helium314.keyboard.settings.SettingsActivity
import helium314.keyboard.settings.Theme import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.WithSmallTitle
import helium314.keyboard.settings.initPreview import helium314.keyboard.settings.initPreview
import helium314.keyboard.settings.layoutFilePicker import helium314.keyboard.settings.layoutFilePicker
import helium314.keyboard.settings.layoutIntent import helium314.keyboard.settings.layoutIntent
@ -441,63 +439,6 @@ private fun MainLayoutRow(
} }
} }
@Composable
private fun WithSmallTitle(
description: String,
content: @Composable () -> Unit,
) {
Column {
Text(description, style = MaterialTheme.typography.titleSmall)
content()
}
}
@Composable
fun <T>DropDownField(
items: List<T>,
selectedItem: T,
onSelected: (T) -> Unit,
extraButton: @Composable (() -> Unit)? = null,
itemContent: @Composable (T) -> Unit,
) {
var expanded by remember { mutableStateOf(false) }
Box(
Modifier.clickable { expanded = !expanded }
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 8.dp, bottom = 4.dp)
) {
Box(Modifier.weight(1f)) {
itemContent(selectedItem)
}
IconButton(
onClick = { expanded = !expanded },
enabled = items.size > 1
) {
Icon(
painterResource(R.drawable.ic_arrow_left),
"show dropdown",
Modifier.rotate(-90f)
)
}
if (extraButton != null)
extraButton()
}
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { expanded = false }
) {
items.forEach {
DropdownMenuItem(
text = { itemContent(it) },
onClick = { expanded = false; onSelected(it) }
)
}
}
}
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() }

View file

@ -32,8 +32,8 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import helium314.keyboard.settings.DropDownField
import helium314.keyboard.settings.SearchScreen import helium314.keyboard.settings.SearchScreen
import helium314.keyboard.settings.dialogs.DropDownField
import helium314.keyboard.settings.dialogs.ThreeButtonAlertDialog import helium314.keyboard.settings.dialogs.ThreeButtonAlertDialog
import java.util.Locale import java.util.Locale

View file

@ -11,7 +11,7 @@
<!-- Title for IME settings screen. The app name should not be translated. --> <!-- Title for IME settings screen. The app name should not be translated. -->
<string name="ime_settings">HeliBoard Settings</string> <string name="ime_settings">HeliBoard Settings</string>
<!-- Title for the spell checking service settings screen. The app name should not be translated. --> <!-- Title for the spell checking service settings screen. The app name should not be translated. -->
<string name="android_spell_checker_settings">HeliBoard Spell Checker Settings</string> <string name="android_spell_checker_settings">HeliBoard Spell Checker Settings</string> <!-- todo: was used in top bar, but spell checker settings now don't have one -->
<!-- Option to provide vibrate/haptic feedback on keypress --> <!-- Option to provide vibrate/haptic feedback on keypress -->
<string name="vibrate_on_keypress">Vibrate on keypress</string> <string name="vibrate_on_keypress">Vibrate on keypress</string>
<!-- Option to provide vibrate/haptic feedback on keypress even in do not disturb mode --> <!-- Option to provide vibrate/haptic feedback on keypress even in do not disturb mode -->