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
dialog {
text = "FUTO Keyboard has crashed! Please send a report to help us fix this."
title = "Crash"
positiveButtonText = "Send Report"
negativeButtonText = "Ignore"
text = getString(R.string.crashed_text)
title = getString(R.string.crashed_title)
positiveButtonText = getString(R.string.crash_report_accept)
negativeButtonText = getString(R.string.crash_report_reject)
resTheme = android.R.style.Theme_DeviceDefault_Dialog
}

View File

@ -2,6 +2,7 @@ package org.futo.inputmethod.latin.uix
import android.content.Context
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.material3.ColorScheme
import androidx.compose.runtime.Composable
import androidx.lifecycle.LifecycleCoroutineScope
@ -52,7 +53,7 @@ interface PersistentActionState {
data class Action(
@DrawableRes val icon: Int,
val name: String, // TODO: @StringRes Int
@StringRes val name: Int,
val windowImpl: ((KeyboardManagerForAction, PersistentActionState?) -> ActionWindow)?,
val simplePressImpl: ((KeyboardManagerForAction, PersistentActionState?) -> Unit)?,
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.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.TextStyle
@ -279,7 +280,7 @@ fun ActionItem(action: Action, onSelect: (Action) -> Unit) {
) {
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()) {
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.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action
@ -18,13 +19,13 @@ import org.futo.inputmethod.latin.uix.theme.ThemeOptions
val ThemeAction = Action(
icon = R.drawable.eye,
name = "Theme Switcher",
name = R.string.theme_switcher_action_title,
simplePressImpl = null,
windowImpl = { manager, _ ->
object : ActionWindow {
@Composable
override fun windowName(): String {
return "Theme Switcher"
return stringResource(R.string.theme_switcher_action_title)
}
@Composable
@ -45,7 +46,7 @@ val ThemeAction = Action(
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.Action
import org.futo.inputmethod.latin.uix.ActionInputTransaction
@ -26,7 +27,7 @@ import org.futo.voiceinput.shared.whisper.ModelManager
val SystemVoiceInputAction = Action(
icon = R.drawable.mic_fill,
name = "Voice Input",
name = R.string.voice_input_action_title,
simplePressImpl = { it, _ ->
it.triggerSystemVoiceInput()
},
@ -45,7 +46,7 @@ class VoiceInputPersistentState(val manager: KeyboardManagerForAction) : Persist
}
val VoiceInputAction = Action(
icon = R.drawable.mic_fill,
name = "Voice Input",
name = R.string.voice_input_action_title,
simplePressImpl = null,
persistentState = { VoiceInputPersistentState(it) },
@ -79,19 +80,21 @@ val VoiceInputAction = Action(
@Composable
override fun windowName(): String {
return "Voice Input"
return stringResource(R.string.voice_input_action_title)
}
@Composable
override fun WindowContents() {
Box(modifier = Modifier.fillMaxSize().clickable(
enabled = true,
onClickLabel = null,
onClick = { recognizerView.finish() },
role = null,
indication = null,
interactionSource = remember { MutableInteractionSource() }
)) {
Box(modifier = Modifier
.fillMaxSize()
.clickable(
enabled = true,
onClickLabel = null,
onClick = { recognizerView.finish() },
role = null,
indication = null,
interactionSource = remember { MutableInteractionSource() }
)) {
Box(modifier = Modifier.align(Alignment.Center)) {
recognizerView.Content()
}

View File

@ -1,6 +1,7 @@
package org.futo.inputmethod.latin.uix.theme
import android.content.Context
import androidx.annotation.StringRes
import androidx.compose.material3.ColorScheme
import org.futo.inputmethod.latin.uix.theme.presets.AMOLEDDarkPurple
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(
val dynamic: Boolean,
val key: String,
val name: String, // TODO: @StringRes Int
@StringRes val name: Int,
val available: (Context) -> Boolean,
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.ui.graphics.Color
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.ThemeOption
private val md_theme_dark_primary = Color(0xFFD0BCFF)
@ -67,6 +68,11 @@ private val colorScheme = darkColorScheme(
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
}

View File

@ -18,6 +18,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.theme.ThemeOption
@ -84,7 +85,12 @@ private val colorScheme = darkColorScheme(
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
}

View File

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

View File

@ -1,8 +1,14 @@
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.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
}