diff --git a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt index 52b2bf8d0..2ca8007be 100644 --- a/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt +++ b/java/src/org/futo/inputmethod/latin/uix/ActionBar.kt @@ -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) diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/Hooks.kt b/java/src/org/futo/inputmethod/latin/uix/settings/Hooks.kt index 3660bd7c8..ad0f2bb55 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/Hooks.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/Hooks.kt @@ -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(val value: T, val setValue: (T) -> Job) @Composable -fun useDataStoreValueNullable(key: Preferences.Key, default: T): T { +fun useDataStoreValueBlocking(key: Preferences.Key, default: T): T { val context = LocalContext.current val initialValue = remember { @@ -50,8 +45,8 @@ fun useDataStoreValueNullable(key: Preferences.Key, default: T): T { } @Composable -fun useDataStoreValueNullable(v: SettingsKey): T { - return useDataStoreValueNullable(key = v.key, default = v.default) +fun useDataStoreValueBlocking(v: SettingsKey): T { + return useDataStoreValueBlocking(key = v.key, default = v.default) } @Composable 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 index add4bf7d6..bffe53b80 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/DevSettings.kt @@ -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) 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 6cef8f8ab..d3de5064b 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 @@ -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) } 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 aa0b9a73b..70250680b 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 @@ -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 { diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt index fc1332ba8..28bdeb891 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt @@ -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) diff --git a/java/src/org/futo/inputmethod/latin/uix/theme/Theme.kt b/java/src/org/futo/inputmethod/latin/uix/theme/Theme.kt index fc6c142e8..5b9d581a9 100644 --- a/java/src/org/futo/inputmethod/latin/uix/theme/Theme.kt +++ b/java/src/org/futo/inputmethod/latin/uix/theme/Theme.kt @@ -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