Add developer settings toggle to developer settings

This commit is contained in:
Aleksandras Kostarevas 2024-04-29 10:10:27 -04:00
parent 579845df45
commit 41b44d434e
7 changed files with 22 additions and 26 deletions

View File

@ -18,7 +18,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyItemScope
@ -76,7 +75,6 @@ import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@ -94,7 +92,7 @@ import org.futo.inputmethod.latin.uix.actions.DefaultActions
import org.futo.inputmethod.latin.uix.actions.DefaultActionsString
import org.futo.inputmethod.latin.uix.actions.ExpandableActionItems
import org.futo.inputmethod.latin.uix.actions.VoiceInputAction
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueNullable
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
import org.futo.inputmethod.latin.uix.theme.Typography
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
@ -483,7 +481,7 @@ fun ActionItemSmall(action: Action, onSelect: (Action) -> Unit) {
@Composable
fun ActionItems(onSelect: (Action) -> Unit) {
val actions = useDataStoreValueNullable(key = ExpandableActionItems, default = DefaultActionsString)
val actions = useDataStoreValueBlocking(key = ExpandableActionItems, default = DefaultActionsString)
if(actions != null) {
val actionItems = ActionRegistry.stringToActions(actions, DefaultActions)

View File

@ -2,13 +2,8 @@ package org.futo.inputmethod.latin.uix.settings
import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.provider.Settings
import android.view.inputmethod.InputMethodManager
import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -31,7 +26,7 @@ import org.futo.inputmethod.latin.uix.getSetting
data class DataStoreItem<T>(val value: T, val setValue: (T) -> Job)
@Composable
fun <T> useDataStoreValueNullable(key: Preferences.Key<T>, default: T): T {
fun <T> useDataStoreValueBlocking(key: Preferences.Key<T>, default: T): T {
val context = LocalContext.current
val initialValue = remember {
@ -50,8 +45,8 @@ fun <T> useDataStoreValueNullable(key: Preferences.Key<T>, default: T): T {
}
@Composable
fun <T> useDataStoreValueNullable(v: SettingsKey<T>): T {
return useDataStoreValueNullable(key = v.key, default = v.default)
fun <T> useDataStoreValueBlocking(v: SettingsKey<T>): T {
return useDataStoreValueBlocking(key = v.key, default = v.default)
}
@Composable

View File

@ -25,7 +25,7 @@ import org.futo.inputmethod.latin.uix.settings.SettingToggleRaw
import org.futo.inputmethod.latin.uix.settings.useDataStore
val IS_DEVELOPER = booleanPreferencesKey("isDeveloperMode")
val IS_DEVELOPER = SettingsKey(booleanPreferencesKey("isDeveloperMode"), false)
@Preview(showBackground = true)
@Composable
@ -36,6 +36,8 @@ fun DeveloperScreen(navController: NavHostController = rememberNavController())
ScrollableList {
ScreenTitle("Developer", showBack = true, navController)
SettingToggleDataStore(title = "Developer mode", setting = IS_DEVELOPER)
SettingToggleDataStore(
title = "Touch typing mode",
subtitle = "Hides all keys. Touch typists only! Recommended to disable emoji key and enable key borders",
@ -56,6 +58,7 @@ fun DeveloperScreen(navController: NavHostController = rememberNavController())
icon = painterResource(id = R.drawable.close)
)
ScreenTitle(title = "Payment stuff")
SettingToggleDataStore(title = "Is paid", setting = IS_ALREADY_PAID)

View File

@ -50,12 +50,12 @@ fun HelpScreen(navController: NavHostController = rememberNavController()) {
it.show()
}
}
if(runBlocking { context.getSetting(IS_DEVELOPER, false) }) {
if(runBlocking { context.getSetting(IS_DEVELOPER) }) {
makeToast("You're already a developer")
} else {
numPresses.value += 1
if (numPresses.value > 3) {
val pressesUntilDeveloper = 8 - numPresses.value
numPresses.intValue += 1
if (numPresses.intValue > 3) {
val pressesUntilDeveloper = 8 - numPresses.intValue
if (pressesUntilDeveloper <= 0) {
makeToast("You're now a developer")
runBlocking { context.setSetting(IS_DEVELOPER, true) }

View File

@ -29,7 +29,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.useDataStoreValueNullable
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
import org.futo.inputmethod.latin.uix.theme.Typography
import org.futo.inputmethod.updates.ConditionalUpdate
@ -59,8 +59,8 @@ fun AndroidTextInput() {
fun HomeScreen(navController: NavHostController = rememberNavController()) {
val context = LocalContext.current
val scrollState = rememberScrollState()
val isDeveloper = useDataStoreValueNullable(key = IS_DEVELOPER, default = false)
val isPaid = useDataStoreValueNullable(IS_ALREADY_PAID)
val isDeveloper = useDataStoreValueBlocking(IS_DEVELOPER)
val isPaid = useDataStoreValueBlocking(IS_ALREADY_PAID)
Column {

View File

@ -58,7 +58,7 @@ 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.useDataStore
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueNullable
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
import org.futo.inputmethod.latin.uix.theme.Typography
import org.futo.inputmethod.updates.openURI
import kotlin.math.absoluteValue
@ -153,9 +153,9 @@ fun UnpaidNoticeCondition(
inner: @Composable () -> Unit
) {
val numDaysInstalled = useNumberOfDaysInstalled()
val forceShowNotice = useDataStoreValueNullable(FORCE_SHOW_NOTICE)
val isAlreadyPaid = useDataStoreValueNullable(IS_ALREADY_PAID)
val pushReminderTime = useDataStoreValueNullable(NOTICE_REMINDER_TIME)
val forceShowNotice = useDataStoreValueBlocking(FORCE_SHOW_NOTICE)
val isAlreadyPaid = useDataStoreValueBlocking(IS_ALREADY_PAID)
val pushReminderTime = useDataStoreValueBlocking(NOTICE_REMINDER_TIME)
val currentTime = System.currentTimeMillis() / 1000L
val reminderTimeIsUp = (currentTime >= pushReminderTime)

View File

@ -15,7 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import org.futo.inputmethod.latin.uix.THEME_KEY
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueNullable
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
import kotlin.math.sqrt
@ -108,7 +108,7 @@ fun ThemeOption?.ensureAvailable(context: Context): ThemeOption? {
fun UixThemeAuto(content: @Composable () -> Unit) {
val context = LocalContext.current
val themeIdx = useDataStoreValueNullable(THEME_KEY.key, THEME_KEY.default)
val themeIdx = useDataStoreValueBlocking(THEME_KEY.key, THEME_KEY.default)
val theme: ThemeOption = themeIdx?.let { ThemeOptions[it].ensureAvailable(context) }
?: VoiceInputTheme