Replace certain hardcoded strings with stringres

This commit is contained in:
Aleksandras Kostarevas 2023-09-01 08:08:13 +03:00
parent cf53d161cc
commit af42223a0c
12 changed files with 75 additions and 28 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="crashed_text">FUTO Keyboard has crashed! Please send a report to help us fix this.</string>
<string name="crashed_title">Crash Reporter</string>
<string name="crash_report_accept">Send Report</string>
<string name="crash_report_reject">Ignore</string>
</resources>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="voice_input_action_title">Voice Input</string>
<string name="theme_switcher_action_title">Theme Switcher</string>
<string name="amoled_dark_theme_name">AMOLED Dark Purple</string>
<string name="classic_material_dark_theme_name">AOSP Material Dark</string>
<string name="voice_input_theme_name">Voice Input Theme</string>
<string name="dynamic_system_theme_name">Dynamic System</string>
<string name="dynamic_light_theme_name">Dynamic Light</string>
<string name="dynamic_dark_theme_name">Dynamic Dark</string>
</resources>

View File

@ -17,10 +17,10 @@ class CrashLoggingApplication : Application() {
reportFormat = StringFormat.JSON reportFormat = StringFormat.JSON
dialog { dialog {
text = "FUTO Keyboard has crashed! Please send a report to help us fix this." text = getString(R.string.crashed_text)
title = "Crash" title = getString(R.string.crashed_title)
positiveButtonText = "Send Report" positiveButtonText = getString(R.string.crash_report_accept)
negativeButtonText = "Ignore" negativeButtonText = getString(R.string.crash_report_reject)
resTheme = android.R.style.Theme_DeviceDefault_Dialog resTheme = android.R.style.Theme_DeviceDefault_Dialog
} }

View File

@ -2,6 +2,7 @@ package org.futo.inputmethod.latin.uix
import android.content.Context import android.content.Context
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.material3.ColorScheme import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.lifecycle.LifecycleCoroutineScope import androidx.lifecycle.LifecycleCoroutineScope
@ -52,7 +53,7 @@ interface PersistentActionState {
data class Action( data class Action(
@DrawableRes val icon: Int, @DrawableRes val icon: Int,
val name: String, // TODO: @StringRes Int @StringRes val name: Int,
val windowImpl: ((KeyboardManagerForAction, PersistentActionState?) -> ActionWindow)?, val windowImpl: ((KeyboardManagerForAction, PersistentActionState?) -> ActionWindow)?,
val simplePressImpl: ((KeyboardManagerForAction, PersistentActionState?) -> Unit)?, val simplePressImpl: ((KeyboardManagerForAction, PersistentActionState?) -> Unit)?,
val persistentState: ((KeyboardManagerForAction) -> PersistentActionState)? = null, val persistentState: ((KeyboardManagerForAction) -> PersistentActionState)? = null,

View File

@ -44,6 +44,7 @@ import androidx.compose.ui.graphics.drawscope.scale
import androidx.compose.ui.graphics.drawscope.translate import androidx.compose.ui.graphics.drawscope.translate
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.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
@ -279,7 +280,7 @@ fun ActionItem(action: Action, onSelect: (Action) -> Unit) {
) { ) {
Icon( Icon(
painter = painterResource(id = action.icon), painter = painterResource(id = action.icon),
contentDescription = action.name contentDescription = stringResource(action.name)
) )
} }
} }
@ -293,7 +294,7 @@ fun ActionItemSmall(action: Action, onSelect: (Action) -> Unit) {
.fillMaxHeight()) { .fillMaxHeight()) {
Icon( Icon(
painter = painterResource(id = action.icon), painter = painterResource(id = action.icon),
contentDescription = action.name contentDescription = stringResource(action.name)
) )
} }
} }

View File

@ -8,6 +8,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action import org.futo.inputmethod.latin.uix.Action
@ -18,13 +19,13 @@ import org.futo.inputmethod.latin.uix.theme.ThemeOptions
val ThemeAction = Action( val ThemeAction = Action(
icon = R.drawable.eye, icon = R.drawable.eye,
name = "Theme Switcher", name = R.string.theme_switcher_action_title,
simplePressImpl = null, simplePressImpl = null,
windowImpl = { manager, _ -> windowImpl = { manager, _ ->
object : ActionWindow { object : ActionWindow {
@Composable @Composable
override fun windowName(): String { override fun windowName(): String {
return "Theme Switcher" return stringResource(R.string.theme_switcher_action_title)
} }
@Composable @Composable
@ -45,7 +46,7 @@ val ThemeAction = Action(
themeOption themeOption
) )
}) { }) {
Text(themeOption.name) Text(stringResource(themeOption.name))
} }
} }
} }

View File

@ -12,6 +12,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import org.futo.inputmethod.latin.R import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action import org.futo.inputmethod.latin.uix.Action
import org.futo.inputmethod.latin.uix.ActionInputTransaction import org.futo.inputmethod.latin.uix.ActionInputTransaction
@ -26,7 +27,7 @@ import org.futo.voiceinput.shared.whisper.ModelManager
val SystemVoiceInputAction = Action( val SystemVoiceInputAction = Action(
icon = R.drawable.mic_fill, icon = R.drawable.mic_fill,
name = "Voice Input", name = R.string.voice_input_action_title,
simplePressImpl = { it, _ -> simplePressImpl = { it, _ ->
it.triggerSystemVoiceInput() it.triggerSystemVoiceInput()
}, },
@ -45,7 +46,7 @@ class VoiceInputPersistentState(val manager: KeyboardManagerForAction) : Persist
} }
val VoiceInputAction = Action( val VoiceInputAction = Action(
icon = R.drawable.mic_fill, icon = R.drawable.mic_fill,
name = "Voice Input", name = R.string.voice_input_action_title,
simplePressImpl = null, simplePressImpl = null,
persistentState = { VoiceInputPersistentState(it) }, persistentState = { VoiceInputPersistentState(it) },
@ -79,12 +80,14 @@ val VoiceInputAction = Action(
@Composable @Composable
override fun windowName(): String { override fun windowName(): String {
return "Voice Input" return stringResource(R.string.voice_input_action_title)
} }
@Composable @Composable
override fun WindowContents() { override fun WindowContents() {
Box(modifier = Modifier.fillMaxSize().clickable( Box(modifier = Modifier
.fillMaxSize()
.clickable(
enabled = true, enabled = true,
onClickLabel = null, onClickLabel = null,
onClick = { recognizerView.finish() }, onClick = { recognizerView.finish() },

View File

@ -1,6 +1,7 @@
package org.futo.inputmethod.latin.uix.theme package org.futo.inputmethod.latin.uix.theme
import android.content.Context import android.content.Context
import androidx.annotation.StringRes
import androidx.compose.material3.ColorScheme import androidx.compose.material3.ColorScheme
import org.futo.inputmethod.latin.uix.theme.presets.AMOLEDDarkPurple import org.futo.inputmethod.latin.uix.theme.presets.AMOLEDDarkPurple
import org.futo.inputmethod.latin.uix.theme.presets.ClassicMaterialDark import org.futo.inputmethod.latin.uix.theme.presets.ClassicMaterialDark
@ -12,7 +13,7 @@ import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
data class ThemeOption( data class ThemeOption(
val dynamic: Boolean, val dynamic: Boolean,
val key: String, val key: String,
val name: String, // TODO: @StringRes Int @StringRes val name: Int,
val available: (Context) -> Boolean, val available: (Context) -> Boolean,
val obtainColors: (Context) -> ColorScheme, val obtainColors: (Context) -> ColorScheme,
) )

View File

@ -2,6 +2,7 @@ package org.futo.inputmethod.latin.uix.theme.presets
import androidx.compose.material3.darkColorScheme import androidx.compose.material3.darkColorScheme
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.ThemeOption
private val md_theme_dark_primary = Color(0xFFD0BCFF) private val md_theme_dark_primary = Color(0xFFD0BCFF)
@ -67,6 +68,11 @@ private val colorScheme = darkColorScheme(
scrim = md_theme_dark_scrim, scrim = md_theme_dark_scrim,
) )
val AMOLEDDarkPurple = ThemeOption(false, "AMOLEDDarkPurple", "AMOLED Dark Purple", { true }) { val AMOLEDDarkPurple = ThemeOption(
dynamic = false,
key = "AMOLEDDarkPurple",
name = R.string.amoled_dark_theme_name,
available = { true }
) {
colorScheme colorScheme
} }

View File

@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.ThemeOption
@ -84,7 +85,12 @@ private val colorScheme = darkColorScheme(
scrim = md_theme_dark_scrim, scrim = md_theme_dark_scrim,
) )
val ClassicMaterialDark = ThemeOption(false, "ClassicMaterialDark", "AOSP Material Dark", { true }) { val ClassicMaterialDark = ThemeOption(
dynamic = false,
key = "ClassicMaterialDark",
name = R.string.classic_material_dark_theme_name,
available = { true }
) {
colorScheme colorScheme
} }

View File

@ -6,12 +6,13 @@ import android.content.res.Configuration
import android.os.Build import android.os.Build
import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.material3.dynamicLightColorScheme
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.ThemeOption
val DynamicSystemTheme = ThemeOption( val DynamicSystemTheme = ThemeOption(
dynamic = true, dynamic = true,
key = "DynamicSystem", key = "DynamicSystem",
name = "Dynamic System", name = R.string.dynamic_system_theme_name,
available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S }, available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S },
obtainColors = { obtainColors = {
val uiModeManager = it.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager val uiModeManager = it.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
@ -34,7 +35,7 @@ val DynamicSystemTheme = ThemeOption(
val DynamicDarkTheme = ThemeOption( val DynamicDarkTheme = ThemeOption(
dynamic = true, dynamic = true,
key = "DynamicDark", key = "DynamicDark",
name = "Dynamic Dark", name = R.string.dynamic_dark_theme_name,
available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S }, available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S },
obtainColors = { obtainColors = {
dynamicDarkColorScheme(it) dynamicDarkColorScheme(it)
@ -44,7 +45,7 @@ val DynamicDarkTheme = ThemeOption(
val DynamicLightTheme = ThemeOption( val DynamicLightTheme = ThemeOption(
dynamic = true, dynamic = true,
key = "DynamicLight", key = "DynamicLight",
name = "Dynamic Light", name = R.string.dynamic_light_theme_name,
available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S }, available = { Build.VERSION.SDK_INT >= Build.VERSION_CODES.S },
obtainColors = { obtainColors = {
dynamicLightColorScheme(it) dynamicLightColorScheme(it)

View File

@ -1,8 +1,14 @@
package org.futo.inputmethod.latin.uix.theme.presets package org.futo.inputmethod.latin.uix.theme.presets
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
import org.futo.inputmethod.latin.uix.theme.ThemeOption import org.futo.inputmethod.latin.uix.theme.ThemeOption
val VoiceInputTheme = ThemeOption(false, "VoiceInputTheme", "Voice Input Theme", { true }) { val VoiceInputTheme = ThemeOption(
dynamic = false,
key = "VoiceInputTheme",
name = R.string.voice_input_theme_name,
available = { true }
) {
DarkColorScheme DarkColorScheme
} }