diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/SettingsNavigator.kt b/java/src/org/futo/inputmethod/latin/uix/settings/SettingsNavigator.kt index d3ec5fd6a..03ae27e19 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/SettingsNavigator.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/SettingsNavigator.kt @@ -12,6 +12,7 @@ import org.futo.inputmethod.latin.uix.ErrorDialog 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.DeveloperScreen 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.LanguagesScreen @@ -48,6 +49,7 @@ fun SettingsNavigator( composable("voiceInput") { VoiceInputScreen(navController) } composable("themes") { ThemeScreen(navController) } composable("help") { HelpScreen(navController) } + composable("developer") { DeveloperScreen(navController) } composable("blacklist") { BlacklistScreen(navController) } dialog("error/{title}/{body}") { ErrorDialog( diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt new file mode 100644 index 000000000..51ab135dd --- /dev/null +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt @@ -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) + ) + } +} \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Help.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Help.kt index c9aa962c2..ddc7fcdfe 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Help.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Help.kt @@ -1,11 +1,19 @@ package org.futo.inputmethod.latin.uix.settings.pages +import android.widget.Toast 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.tooling.preview.Preview import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController +import kotlinx.coroutines.runBlocking 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.NavigationItemStyle import org.futo.inputmethod.latin.uix.settings.ScreenTitle @@ -18,9 +26,47 @@ import org.futo.inputmethod.updates.openURI fun HelpScreen(navController: NavHostController = rememberNavController()) { val context = LocalContext.current + val numPresses = remember { mutableIntStateOf(0) } + var lastToast: MutableState = remember { mutableStateOf(null) } + ScrollableList { 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}") NavigationItem(title = "Wiki", style = NavigationItemStyle.Misc, navigate = { diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt index 6cc06901f..0222a2639 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Home.kt @@ -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.NavigationItemStyle 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.updates.ConditionalUpdate @@ -47,7 +47,9 @@ fun AndroidTextInput() { 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()) { val context = LocalContext.current val scrollState = rememberScrollState() + val isDeveloper = useDataStore(key = IS_DEVELOPER, default = false) + Column { Column( modifier = Modifier - .weight(1.0f).fillMaxWidth() + .weight(1.0f) + .fillMaxWidth() .verticalScroll(scrollState) ) { Spacer(modifier = Modifier.height(24.dp)) @@ -109,6 +114,15 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) { 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)) Text( diff --git a/java/src/org/futo/inputmethod/updates/Update.kt b/java/src/org/futo/inputmethod/updates/Update.kt index d8b12ab4a..5bf4d543f 100644 --- a/java/src/org/futo/inputmethod/updates/Update.kt +++ b/java/src/org/futo/inputmethod/updates/Update.kt @@ -69,8 +69,8 @@ fun ConditionalUpdate(navController: NavHostController) { } } else if(lastFailed) { SettingItem( - title = "Failed to check for updates", - subtitle = "Tap to check manually", + title = "Unable to check online for updates", + subtitle = "Please tap to check manually", onClick = { context.openManualUpdateCheck() }