Add languages menu

This commit is contained in:
Aleksandras Kostarevas 2024-03-25 13:07:10 -05:00
parent a9b8e9de22
commit 14fa302f1f
3 changed files with 82 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import org.futo.inputmethod.latin.uix.InfoDialog
import org.futo.inputmethod.latin.uix.settings.pages.AdvancedParametersScreen
import org.futo.inputmethod.latin.uix.settings.pages.BlacklistScreen
import org.futo.inputmethod.latin.uix.settings.pages.HomeScreen
import org.futo.inputmethod.latin.uix.settings.pages.LanguagesScreen
import org.futo.inputmethod.latin.uix.settings.pages.PredictiveTextScreen
import org.futo.inputmethod.latin.uix.settings.pages.ThemeScreen
import org.futo.inputmethod.latin.uix.settings.pages.TypingScreen
@ -39,6 +40,7 @@ fun SettingsNavigator(
startDestination = "home"
) {
composable("home") { HomeScreen(navController) }
composable("languages") { LanguagesScreen(navController) }
composable("predictiveText") { PredictiveTextScreen(navController) }
composable("advancedparams") { AdvancedParametersScreen(navController) }
composable("typing") { TypingScreen(navController) }

View File

@ -70,7 +70,7 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) {
NavigationItem(
title = "Languages",
style = NavigationItemStyle.HomePrimary,
navigate = { context.openLanguageSettings() },
navigate = { navController.navigate("languages") },
icon = painterResource(id = R.drawable.globe)
)

View File

@ -0,0 +1,79 @@
package org.futo.inputmethod.latin.uix.settings.pages
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.RichInputMethodManager
import org.futo.inputmethod.latin.uix.settings.NavigationItem
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
import org.futo.inputmethod.latin.uix.settings.ScreenTitle
import org.futo.inputmethod.latin.uix.settings.ScrollableList
import org.futo.inputmethod.latin.uix.settings.Tip
import org.futo.inputmethod.latin.uix.settings.openLanguageSettings
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils
import org.futo.inputmethod.updates.openURI
data class LanguageOptions(
val voiceInputModel: String?,
val dictionary: String?,
val transformerModel: String?
)
@Preview
@Composable
fun LanguagesScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current
ScrollableList {
ScreenTitle("Languages", showBack = true, navController)
NavigationItem(
title = "Enable/disable languages",
style = NavigationItemStyle.Misc,
navigate = { context.openLanguageSettings() },
)
Tip("Note: The list below will only update after opening the keyboard")
RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(true).forEach {
val name = SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(it)
val dummyOptions = LanguageOptions(
voiceInputModel = "Built-in English-39",
dictionary = "main.dict",
transformerModel = null
)
ScreenTitle(name)
NavigationItem(
title = dummyOptions.voiceInputModel ?: "None",
style = dummyOptions.voiceInputModel?.let { NavigationItemStyle.HomeTertiary } ?: NavigationItemStyle.MiscNoArrow,
navigate = {
context.openURI("https://keyboard.futo.org/voice-input-models", true)
},
icon = painterResource(id = R.drawable.mic_fill)
)
NavigationItem(
title = dummyOptions.dictionary ?: "None",
style = dummyOptions.dictionary?.let { NavigationItemStyle.HomeTertiary } ?: NavigationItemStyle.MiscNoArrow,
navigate = {
context.openURI("https://codeberg.org/Helium314/aosp-dictionaries#dictionaries", true)
},
icon = painterResource(id = R.drawable.book)
)
NavigationItem(
title = dummyOptions.transformerModel ?: "None",
style = dummyOptions.transformerModel?.let { NavigationItemStyle.HomeTertiary } ?: NavigationItemStyle.MiscNoArrow,
navigate = {
context.openURI("https://keyboard.futo.org/models", true)
},
icon = painterResource(id = R.drawable.cpu)
)
}
}
}