Add developer settings menu

This commit is contained in:
Aleksandras Kostarevas 2024-04-02 16:56:40 -05:00
parent 2a4840d794
commit 5649668bfb
5 changed files with 115 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import org.futo.inputmethod.latin.uix.ErrorDialog
import org.futo.inputmethod.latin.uix.InfoDialog import org.futo.inputmethod.latin.uix.InfoDialog
import org.futo.inputmethod.latin.uix.settings.pages.AdvancedParametersScreen 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.BlacklistScreen
import org.futo.inputmethod.latin.uix.settings.pages.DeveloperScreen
import org.futo.inputmethod.latin.uix.settings.pages.HelpScreen import org.futo.inputmethod.latin.uix.settings.pages.HelpScreen
import org.futo.inputmethod.latin.uix.settings.pages.HomeScreen 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.LanguagesScreen
@ -48,6 +49,7 @@ fun SettingsNavigator(
composable("voiceInput") { VoiceInputScreen(navController) } composable("voiceInput") { VoiceInputScreen(navController) }
composable("themes") { ThemeScreen(navController) } composable("themes") { ThemeScreen(navController) }
composable("help") { HelpScreen(navController) } composable("help") { HelpScreen(navController) }
composable("developer") { DeveloperScreen(navController) }
composable("blacklist") { BlacklistScreen(navController) } composable("blacklist") { BlacklistScreen(navController) }
dialog("error/{title}/{body}") { dialog("error/{title}/{body}") {
ErrorDialog( ErrorDialog(

View File

@ -0,0 +1,48 @@
package org.futo.inputmethod.latin.uix.settings.pages
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.futo.inputmethod.latin.R
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
val IS_DEVELOPER = booleanPreferencesKey("isDeveloperMode")
@Preview(showBackground = true)
@Composable
fun DeveloperScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current
val scope = LocalLifecycleOwner.current
ScrollableList {
ScreenTitle("Developer", showBack = true, navController)
NavigationItem(
title = "Crash the app",
style = NavigationItemStyle.MiscNoArrow,
navigate = {
scope.lifecycleScope.launch {
withContext(Dispatchers.Default) {
delay(300L)
throw RuntimeException("User requested app to crash :3")
}
}
},
icon = painterResource(id = R.drawable.close)
)
}
}

View File

@ -1,11 +1,19 @@
package org.futo.inputmethod.latin.uix.settings.pages package org.futo.inputmethod.latin.uix.settings.pages
import android.widget.Toast
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import kotlinx.coroutines.runBlocking
import org.futo.inputmethod.latin.BuildConfig import org.futo.inputmethod.latin.BuildConfig
import org.futo.inputmethod.latin.uix.getSetting
import org.futo.inputmethod.latin.uix.setSetting
import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItem
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
import org.futo.inputmethod.latin.uix.settings.ScreenTitle import org.futo.inputmethod.latin.uix.settings.ScreenTitle
@ -18,9 +26,47 @@ import org.futo.inputmethod.updates.openURI
fun HelpScreen(navController: NavHostController = rememberNavController()) { fun HelpScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current val context = LocalContext.current
val numPresses = remember { mutableIntStateOf(0) }
var lastToast: MutableState<Toast?> = remember { mutableStateOf(null) }
ScrollableList { ScrollableList {
ScreenTitle("Help & Feedback", showBack = true, navController) ScreenTitle("Help & Feedback", showBack = true, navController)
NavigationItem(
title = "Version Name: ${BuildConfig.VERSION_NAME}",
style = NavigationItemStyle.MiscNoArrow,
navigate = {
}
)
NavigationItem(
title = "Version Code: ${BuildConfig.VERSION_CODE}",
style = NavigationItemStyle.MiscNoArrow,
navigate = {
val makeToast: (String) -> Unit = { text ->
Toast.makeText(context, text, Toast.LENGTH_SHORT).let {
lastToast.value?.cancel()
lastToast.value = it
it.show()
}
}
if(runBlocking { context.getSetting(IS_DEVELOPER, false) }) {
makeToast("You're already a developer")
} else {
numPresses.value += 1
if (numPresses.value > 3) {
val pressesUntilDeveloper = 8 - numPresses.value
if (pressesUntilDeveloper <= 0) {
makeToast("You're now a developer")
runBlocking { context.setSetting(IS_DEVELOPER, true) }
} else {
makeToast("You are $pressesUntilDeveloper steps until becoming a developer")
}
}
}
}
)
Tip("We want to hear from you! If you're reporting an issue, your version may be relevant: v${BuildConfig.VERSION_NAME}") Tip("We want to hear from you! If you're reporting an issue, your version may be relevant: v${BuildConfig.VERSION_NAME}")
NavigationItem(title = "Wiki", style = NavigationItemStyle.Misc, navigate = { NavigationItem(title = "Wiki", style = NavigationItemStyle.Misc, navigate = {

View File

@ -28,7 +28,7 @@ import org.futo.inputmethod.latin.R
import org.futo.inputmethod.latin.uix.settings.NavigationItem import org.futo.inputmethod.latin.uix.settings.NavigationItem
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
import org.futo.inputmethod.latin.uix.settings.ScreenTitle import org.futo.inputmethod.latin.uix.settings.ScreenTitle
import org.futo.inputmethod.latin.uix.settings.openLanguageSettings import org.futo.inputmethod.latin.uix.settings.useDataStore
import org.futo.inputmethod.latin.uix.theme.Typography import org.futo.inputmethod.latin.uix.theme.Typography
import org.futo.inputmethod.updates.ConditionalUpdate import org.futo.inputmethod.updates.ConditionalUpdate
@ -47,7 +47,9 @@ fun AndroidTextInput() {
setHintTextColor(fgColor.copy(alpha = 0.7f).toArgb()) setHintTextColor(fgColor.copy(alpha = 0.7f).toArgb())
} }
} }
AndroidView({ editText }, modifier = Modifier.fillMaxWidth().padding(8.dp)) AndroidView({ editText }, modifier = Modifier
.fillMaxWidth()
.padding(8.dp))
} }
} }
@ -56,10 +58,13 @@ fun AndroidTextInput() {
fun HomeScreen(navController: NavHostController = rememberNavController()) { fun HomeScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current val context = LocalContext.current
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
val isDeveloper = useDataStore(key = IS_DEVELOPER, default = false)
Column { Column {
Column( Column(
modifier = Modifier modifier = Modifier
.weight(1.0f).fillMaxWidth() .weight(1.0f)
.fillMaxWidth()
.verticalScroll(scrollState) .verticalScroll(scrollState)
) { ) {
Spacer(modifier = Modifier.height(24.dp)) Spacer(modifier = Modifier.height(24.dp))
@ -109,6 +114,15 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) {
icon = painterResource(id = R.drawable.help_circle) icon = painterResource(id = R.drawable.help_circle)
) )
if(isDeveloper.value || LocalInspectionMode.current) {
NavigationItem(
title = "Developer Settings",
style = NavigationItemStyle.HomeSecondary,
navigate = { navController.navigate("developer") },
icon = painterResource(id = R.drawable.code)
)
}
Spacer(modifier = Modifier.height(32.dp)) Spacer(modifier = Modifier.height(32.dp))
Text( Text(

View File

@ -69,8 +69,8 @@ fun ConditionalUpdate(navController: NavHostController) {
} }
} else if(lastFailed) { } else if(lastFailed) {
SettingItem( SettingItem(
title = "Failed to check for updates", title = "Unable to check online for updates",
subtitle = "Tap to check manually", subtitle = "Please tap to check manually",
onClick = { onClick = {
context.openManualUpdateCheck() context.openManualUpdateCheck()
} }