mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Optimize method for obtaining DataStore values in Compose
This commit is contained in:
parent
e53ef1094a
commit
26de44f979
@ -44,7 +44,7 @@ import org.futo.inputmethod.latin.uix.settings.NavigationItem
|
||||
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
|
||||
import org.futo.inputmethod.latin.uix.settings.SettingsActivity
|
||||
import org.futo.inputmethod.latin.uix.settings.pages.LocaleLayoutMap
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.latin.utils.SubtypeLocaleUtils
|
||||
import java.util.Locale
|
||||
@ -288,7 +288,7 @@ fun LanguageSwitcherDialog(
|
||||
val subtypeSet = if(inspection) {
|
||||
setOf("en_US:", "pt_PT:", "lt:", "fr:KeyboardLayoutSet=bepo:")
|
||||
} else {
|
||||
useDataStoreValueBlocking(SubtypesSetting)
|
||||
useDataStoreValue(SubtypesSetting)
|
||||
}
|
||||
|
||||
val subtypes = remember(subtypeSet) {
|
||||
@ -300,7 +300,7 @@ fun LanguageSwitcherDialog(
|
||||
val activeSubtype = if(inspection) {
|
||||
"pt_PT:"
|
||||
} else {
|
||||
useDataStoreValueBlocking(ActiveSubtype)
|
||||
useDataStoreValue(ActiveSubtype)
|
||||
}
|
||||
|
||||
Surface(shape = RoundedCornerShape(48.dp), color = MaterialTheme.colorScheme.background) {
|
||||
|
@ -11,6 +11,7 @@ import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import kotlinx.coroutines.launch
|
||||
import org.futo.inputmethod.latin.uix.settings.DataStoreCacheProvider
|
||||
import org.futo.inputmethod.latin.uix.settings.pages.PaymentScreenSwitch
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeAuto
|
||||
|
||||
@ -18,14 +19,16 @@ import org.futo.inputmethod.latin.uix.theme.UixThemeAuto
|
||||
class PaymentActivity : ComponentActivity() {
|
||||
private fun updateContent() {
|
||||
setContent {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
PaymentScreenSwitch(onExit = {
|
||||
finish()
|
||||
})
|
||||
DataStoreCacheProvider {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
PaymentScreenSwitch(onExit = {
|
||||
finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import kotlinx.coroutines.launch
|
||||
import org.futo.inputmethod.latin.R
|
||||
import org.futo.inputmethod.latin.uix.dataStore
|
||||
import org.futo.inputmethod.latin.uix.getSetting
|
||||
import org.futo.inputmethod.latin.uix.settings.DataStoreCacheProvider
|
||||
import org.futo.inputmethod.latin.uix.settings.NavigationItem
|
||||
import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
|
||||
import org.futo.inputmethod.latin.uix.settings.SettingsActivity
|
||||
@ -34,15 +35,17 @@ import org.futo.inputmethod.updates.openURI
|
||||
class PaymentCompleteActivity : ComponentActivity() {
|
||||
private fun updateContent() {
|
||||
setContent {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
PaymentThankYouScreen(onExit = {
|
||||
startAppActivity(SettingsActivity::class.java, clearTop = true)
|
||||
finish()
|
||||
})
|
||||
DataStoreCacheProvider {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
PaymentThankYouScreen(onExit = {
|
||||
startAppActivity(SettingsActivity::class.java, clearTop = true)
|
||||
finish()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -68,20 +71,25 @@ class PaymentCompleteActivity : ComponentActivity() {
|
||||
finish()
|
||||
} else {
|
||||
setContent {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
getString(R.string.license_check_failed),
|
||||
modifier = Modifier.padding(8.dp)
|
||||
)
|
||||
DataStoreCacheProvider {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
getString(R.string.license_check_failed),
|
||||
modifier = Modifier.padding(8.dp)
|
||||
)
|
||||
|
||||
NavigationItem(title = "Email keyboard@futo.org", style = NavigationItemStyle.Mail, navigate = {
|
||||
openURI("mailto:keyboard@futo.org")
|
||||
})
|
||||
NavigationItem(
|
||||
title = "Email keyboard@futo.org",
|
||||
style = NavigationItemStyle.Mail,
|
||||
navigate = {
|
||||
openURI("mailto:keyboard@futo.org")
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ import org.futo.inputmethod.latin.uix.actions.MoreActionsAction
|
||||
import org.futo.inputmethod.latin.uix.actions.PinnedActions
|
||||
import org.futo.inputmethod.latin.uix.actions.toActionList
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.inputmethod.latin.uix.theme.DarkColorScheme
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
||||
@ -450,7 +450,7 @@ fun ActionItems(onSelect: (Action) -> Unit, onLongSelect: (Action) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val lifecycle = LocalLifecycleOwner.current
|
||||
val actions = if(!LocalInspectionMode.current) {
|
||||
useDataStoreValueBlocking(FavoriteActions)
|
||||
useDataStoreValue(FavoriteActions)
|
||||
} else {
|
||||
FavoriteActions.default
|
||||
}
|
||||
@ -630,7 +630,7 @@ fun ImportantNoticeView(
|
||||
@Composable
|
||||
fun RowScope.PinnedActionItems(onSelect: (Action) -> Unit, onLongSelect: (Action) -> Unit) {
|
||||
val actions = if(!LocalInspectionMode.current) {
|
||||
useDataStoreValueBlocking(PinnedActions)
|
||||
useDataStoreValue(PinnedActions)
|
||||
} else {
|
||||
PinnedActions.default
|
||||
}
|
||||
|
@ -77,6 +77,7 @@ import org.futo.inputmethod.latin.uix.actions.ActionEditor
|
||||
import org.futo.inputmethod.latin.uix.actions.ActionRegistry
|
||||
import org.futo.inputmethod.latin.uix.actions.AllActions
|
||||
import org.futo.inputmethod.latin.uix.actions.EmojiAction
|
||||
import org.futo.inputmethod.latin.uix.settings.DataStoreCacheProvider
|
||||
import org.futo.inputmethod.latin.uix.settings.SettingsActivity
|
||||
import org.futo.inputmethod.latin.uix.settings.pages.ActionBarDisplayedSetting
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStore
|
||||
@ -553,10 +554,12 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
|
||||
// Create new dialog
|
||||
languageSwitcherDialog = createDialogComposeView(latinIME) {
|
||||
UixThemeAuto {
|
||||
LanguageSwitcherDialog(
|
||||
onDismiss = { it.dismiss() }
|
||||
)
|
||||
DataStoreCacheProvider {
|
||||
UixThemeAuto {
|
||||
LanguageSwitcherDialog(
|
||||
onDismiss = { it.dismiss() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -607,38 +610,40 @@ class UixManager(private val latinIME: LatinIME) {
|
||||
fun setContent() {
|
||||
composeView?.setContent {
|
||||
UixThemeWrapper(latinIME.colorScheme) {
|
||||
CompositionLocalProvider(LocalManager provides keyboardManagerForAction) {
|
||||
CompositionLocalProvider(LocalThemeProvider provides latinIME.getDrawableProvider()) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
||||
InputDarkener(isInputOverridden.value || isShowingActionEditor.value) {
|
||||
closeActionWindow()
|
||||
isShowingActionEditor.value = false
|
||||
}
|
||||
DataStoreCacheProvider {
|
||||
CompositionLocalProvider(LocalManager provides keyboardManagerForAction) {
|
||||
CompositionLocalProvider(LocalThemeProvider provides latinIME.getDrawableProvider()) {
|
||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
||||
InputDarkener(isInputOverridden.value || isShowingActionEditor.value) {
|
||||
closeActionWindow()
|
||||
isShowingActionEditor.value = false
|
||||
}
|
||||
|
||||
Column {
|
||||
Spacer(modifier = Modifier.weight(1.0f))
|
||||
Surface(modifier = Modifier.onSizeChanged {
|
||||
latinIME.updateTouchableHeight(it.height)
|
||||
}, color = latinIME.keyboardColor) {
|
||||
Box {
|
||||
Column {
|
||||
when {
|
||||
currWindowActionWindow != null -> ActionViewWithHeader(
|
||||
currWindowActionWindow!!
|
||||
)
|
||||
Column {
|
||||
Spacer(modifier = Modifier.weight(1.0f))
|
||||
Surface(modifier = Modifier.onSizeChanged {
|
||||
latinIME.updateTouchableHeight(it.height)
|
||||
}, color = latinIME.keyboardColor) {
|
||||
Box {
|
||||
Column {
|
||||
when {
|
||||
currWindowActionWindow != null -> ActionViewWithHeader(
|
||||
currWindowActionWindow!!
|
||||
)
|
||||
|
||||
else -> MainKeyboardViewWithActionBar()
|
||||
else -> MainKeyboardViewWithActionBar()
|
||||
}
|
||||
|
||||
latinIME.LegacyKeyboardView(hidden = isMainKeyboardHidden)
|
||||
}
|
||||
|
||||
latinIME.LegacyKeyboardView(hidden = isMainKeyboardHidden)
|
||||
ForgetWordDialog()
|
||||
}
|
||||
|
||||
ForgetWordDialog()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ActionEditorHost()
|
||||
ActionEditorHost()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ import org.futo.inputmethod.latin.uix.ActionWindow
|
||||
import org.futo.inputmethod.latin.uix.LocalManager
|
||||
import org.futo.inputmethod.latin.uix.getSettingBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.Tip
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.voiceinput.shared.ui.theme.Typography
|
||||
import sh.calvin.reorderable.ReorderableItem
|
||||
import sh.calvin.reorderable.rememberReorderableLazyGridState
|
||||
@ -104,7 +104,7 @@ fun MoreActionsView() {
|
||||
val actionList = if(LocalInspectionMode.current) {
|
||||
ActionsSettings.default
|
||||
} else {
|
||||
useDataStoreValueBlocking(ActionsSettings)
|
||||
useDataStoreValue(ActionsSettings)
|
||||
}
|
||||
|
||||
val actions = remember(actionList) {
|
||||
|
@ -2,76 +2,64 @@ package org.futo.inputmethod.latin.uix.settings
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.core.content.edit
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.futo.inputmethod.latin.uix.PreferenceUtils
|
||||
import org.futo.inputmethod.latin.uix.SettingsKey
|
||||
import org.futo.inputmethod.latin.uix.dataStore
|
||||
import org.futo.inputmethod.latin.uix.getSetting
|
||||
|
||||
class DataStoreCache(
|
||||
val currPreferences: Preferences
|
||||
)
|
||||
|
||||
val LocalDataStoreCache = staticCompositionLocalOf<DataStoreCache?> {
|
||||
null
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DataStoreCacheProvider(content: @Composable () -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val initialPrefs = remember {
|
||||
runBlocking {
|
||||
context.dataStore.data.first()
|
||||
}
|
||||
}
|
||||
val prefs = context.dataStore.data.collectAsState(initialPrefs)
|
||||
|
||||
val cache = remember(prefs.value) {
|
||||
DataStoreCache(prefs.value)
|
||||
}
|
||||
|
||||
CompositionLocalProvider(LocalDataStoreCache provides cache) {
|
||||
content()
|
||||
}
|
||||
}
|
||||
|
||||
data class DataStoreItem<T>(val value: T, val setValue: (T) -> Job)
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStoreValueBlocking(key: Preferences.Key<T>, default: T): T {
|
||||
val context = LocalContext.current
|
||||
|
||||
val initialValue = remember {
|
||||
runBlocking {
|
||||
context.getSetting(key, default)
|
||||
}
|
||||
}
|
||||
|
||||
val valueFlow: Flow<T> = remember {
|
||||
context.dataStore.data.map { preferences ->
|
||||
preferences[key] ?: default
|
||||
}
|
||||
}
|
||||
|
||||
return valueFlow.collectAsState(initial = initialValue).value
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStoreValueBlocking(v: SettingsKey<T>): T {
|
||||
return useDataStoreValueBlocking(key = v.key, default = v.default)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStore(key: Preferences.Key<T>, default: T, blocking: Boolean = false): DataStoreItem<T> {
|
||||
val context = LocalContext.current
|
||||
val cache = LocalDataStoreCache.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val initialValue = remember {
|
||||
if(blocking) {
|
||||
runBlocking {
|
||||
context.getSetting(key, default)
|
||||
}
|
||||
} else {
|
||||
default
|
||||
}
|
||||
}
|
||||
|
||||
val valueFlow: Flow<T> = remember {
|
||||
context.dataStore.data.map { preferences ->
|
||||
preferences[key] ?: default
|
||||
}
|
||||
}
|
||||
|
||||
val value = valueFlow.collectAsState(initial = initialValue).value!!
|
||||
val value = cache?.currPreferences?.get(key) ?: default
|
||||
|
||||
val setValue = { newValue: T ->
|
||||
coroutineScope.launch {
|
||||
@ -84,6 +72,13 @@ fun <T> useDataStore(key: Preferences.Key<T>, default: T, blocking: Boolean = fa
|
||||
return DataStoreItem(value, setValue)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStoreValue(settingsKey: SettingsKey<T>): T {
|
||||
val cache = LocalDataStoreCache.current
|
||||
|
||||
return cache?.currPreferences?.get(settingsKey.key) ?: settingsKey.default
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStore(key: SettingsKey<T>, blocking: Boolean = false): DataStoreItem<T> {
|
||||
@ -159,11 +154,11 @@ fun useSharedPrefsInt(key: String, default: Int): DataStoreItem<Int> {
|
||||
private fun<T> SyncDataStoreToPreferences(key: SettingsKey<T>, update: (newValue: T, editor: SharedPreferences.Editor) -> Unit) {
|
||||
val context = LocalContext.current
|
||||
val sharedPrefs = remember { PreferenceUtils.getDefaultSharedPreferences(context) }
|
||||
val value = useDataStoreValueBlocking(key)
|
||||
val value = useDataStore(key)
|
||||
|
||||
LaunchedEffect(value) {
|
||||
val edit = sharedPrefs.edit {
|
||||
update(value, this)
|
||||
update(value.value, this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,18 +6,22 @@ import android.content.Context
|
||||
import android.content.Context.INPUT_METHOD_SERVICE
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.safeDrawingPadding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
@ -39,14 +43,14 @@ import org.futo.inputmethod.latin.uix.USE_SYSTEM_VOICE_INPUT
|
||||
import org.futo.inputmethod.latin.uix.deferGetSetting
|
||||
import org.futo.inputmethod.latin.uix.getSetting
|
||||
import org.futo.inputmethod.latin.uix.getSettingFlow
|
||||
import org.futo.inputmethod.latin.uix.theme.StatusBarColorSetter
|
||||
import org.futo.inputmethod.latin.uix.theme.ThemeOption
|
||||
import org.futo.inputmethod.latin.uix.theme.ThemeOptions
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeAuto
|
||||
import org.futo.inputmethod.latin.uix.theme.presets.VoiceInputTheme
|
||||
import org.futo.inputmethod.latin.xlm.ModelPaths
|
||||
import org.futo.inputmethod.updates.checkForUpdateAndSaveToPreferences
|
||||
import java.io.File
|
||||
import kotlin.math.sqrt
|
||||
|
||||
private fun Context.isInputMethodEnabled(): Boolean {
|
||||
val packageName = packageName
|
||||
@ -153,17 +157,22 @@ class SettingsActivity : ComponentActivity(), DynamicThemeProviderOwner {
|
||||
|
||||
private fun updateContent() {
|
||||
setContent {
|
||||
themeOption.value?.let { themeOption ->
|
||||
val themeIdx = useDataStore(key = THEME_KEY.key, default = themeOption.key)
|
||||
val theme: ThemeOption = ThemeOptions[themeIdx.value] ?: themeOption
|
||||
UixThemeWrapper(theme.obtainColors(LocalContext.current)) {
|
||||
StatusBarColorSetter()
|
||||
DataStoreCacheProvider {
|
||||
UixThemeAuto {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
modifier = Modifier
|
||||
.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
SetupOrMain(inputMethodEnabled.value, inputMethodSelected.value, micPermissionGrantedOrUsingSystem.value, doublePackage.value) {
|
||||
SettingsNavigator(navController = navController)
|
||||
Box(Modifier.safeDrawingPadding()) {
|
||||
SetupOrMain(
|
||||
inputMethodEnabled.value,
|
||||
inputMethodSelected.value,
|
||||
micPermissionGrantedOrUsingSystem.value,
|
||||
doublePackage.value
|
||||
) {
|
||||
SettingsNavigator(navController = navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,6 +183,8 @@ class SettingsActivity : ComponentActivity(), DynamicThemeProviderOwner {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
enableEdgeToEdge()
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
updateSystemState()
|
||||
@ -199,6 +210,8 @@ class SettingsActivity : ComponentActivity(), DynamicThemeProviderOwner {
|
||||
context = this@SettingsActivity,
|
||||
overrideColorScheme = themeOption.obtainColors(this@SettingsActivity)
|
||||
)
|
||||
|
||||
updateEdgeToEdge()
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,6 +224,12 @@ class SettingsActivity : ComponentActivity(), DynamicThemeProviderOwner {
|
||||
}
|
||||
|
||||
this.themeOption.value = themeOption
|
||||
this.themeProvider = BasicThemeProvider(
|
||||
context = this@SettingsActivity,
|
||||
overrideColorScheme = themeOption.obtainColors(this@SettingsActivity)
|
||||
)
|
||||
|
||||
updateEdgeToEdge()
|
||||
}
|
||||
|
||||
val intent = intent
|
||||
@ -279,4 +298,29 @@ class SettingsActivity : ComponentActivity(), DynamicThemeProviderOwner {
|
||||
override fun getDrawableProvider(): DynamicThemeProvider {
|
||||
return themeProvider!!
|
||||
}
|
||||
|
||||
fun updateEdgeToEdge() {
|
||||
themeProvider?.let {
|
||||
val color = it.primaryKeyboardColor
|
||||
|
||||
val luminance = sqrt(
|
||||
0.299 * Color.red(color) / 255.0
|
||||
+ 0.587 * Color.green(color) / 255.0
|
||||
+ 0.114 * Color.blue(color) / 255.0
|
||||
)
|
||||
|
||||
if (luminance > 0.5 && color != android.graphics.Color.TRANSPARENT) {
|
||||
enableEdgeToEdge(
|
||||
SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
|
||||
)
|
||||
} else {
|
||||
enableEdgeToEdge(
|
||||
SystemBarStyle.dark(Color.TRANSPARENT),
|
||||
SystemBarStyle.dark(Color.TRANSPARENT)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ import org.futo.inputmethod.latin.uix.USE_SYSTEM_VOICE_INPUT
|
||||
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.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.updates.ConditionalMigrateUpdateNotice
|
||||
import org.futo.inputmethod.updates.ConditionalUpdate
|
||||
@ -38,8 +38,8 @@ import org.futo.inputmethod.updates.ConditionalUpdate
|
||||
fun HomeScreen(navController: NavHostController = rememberNavController()) {
|
||||
val context = LocalContext.current
|
||||
val scrollState = rememberScrollState()
|
||||
val isDeveloper = useDataStoreValueBlocking(IS_DEVELOPER)
|
||||
val isPaid = useDataStoreValueBlocking(IS_ALREADY_PAID)
|
||||
val isDeveloper = useDataStoreValue(IS_DEVELOPER)
|
||||
val isPaid = useDataStoreValue(IS_ALREADY_PAID)
|
||||
|
||||
|
||||
Column {
|
||||
@ -80,7 +80,7 @@ fun HomeScreen(navController: NavHostController = rememberNavController()) {
|
||||
NavigationItem(
|
||||
title = "Voice Input",
|
||||
style = NavigationItemStyle.HomePrimary,
|
||||
subtitle = if(useDataStoreValueBlocking(USE_SYSTEM_VOICE_INPUT)) { "Built-in voice input is disabled!" } else { null },
|
||||
subtitle = if(useDataStoreValue(USE_SYSTEM_VOICE_INPUT)) { "Built-in voice input is disabled!" } else { null },
|
||||
navigate = { navController.navigate("voiceInput") },
|
||||
icon = painterResource(id = R.drawable.mic_fill)
|
||||
)
|
||||
|
@ -61,7 +61,7 @@ import org.futo.inputmethod.latin.uix.settings.NavigationItemStyle
|
||||
import org.futo.inputmethod.latin.uix.settings.ScreenTitle
|
||||
import org.futo.inputmethod.latin.uix.settings.Tip
|
||||
import org.futo.inputmethod.latin.uix.settings.pages.modelmanager.openModelImporter
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
||||
import org.futo.inputmethod.latin.uix.theme.presets.DynamicDarkTheme
|
||||
@ -401,7 +401,7 @@ fun LanguagesScreen(navController: NavHostController = rememberNavController())
|
||||
val deleteDialogInfo: MutableState<DeleteInfo?> = remember { mutableStateOf(null) }
|
||||
val languageDeleteInfo: MutableState<Locale?> = remember { mutableStateOf(null) }
|
||||
|
||||
val inputMethods = useDataStoreValueBlocking(SubtypesSetting)
|
||||
val inputMethods = useDataStoreValue(SubtypesSetting)
|
||||
val inputMethodList = remember(inputMethods) {
|
||||
Subtypes.layoutsMappedByLanguage(inputMethods)
|
||||
}
|
||||
|
@ -75,7 +75,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.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
import org.futo.inputmethod.latin.uix.theme.Typography
|
||||
import org.futo.inputmethod.latin.uix.theme.UixThemeWrapper
|
||||
import org.futo.inputmethod.latin.uix.theme.presets.DynamicDarkTheme
|
||||
@ -210,16 +210,16 @@ fun UnpaidNoticeCondition(
|
||||
force: Boolean = LocalInspectionMode.current,
|
||||
inner: @Composable () -> Unit
|
||||
) {
|
||||
val paymentUrl = useDataStoreValueBlocking(TMP_PAYMENT_URL)
|
||||
val paymentUrl = useDataStoreValue(TMP_PAYMENT_URL)
|
||||
if(paymentUrl.isBlank()) return
|
||||
|
||||
val numDaysInstalled = useNumberOfDaysInstalled()
|
||||
val forceShowNotice = useDataStoreValueBlocking(FORCE_SHOW_NOTICE)
|
||||
val isAlreadyPaid = useDataStoreValueBlocking(IS_ALREADY_PAID)
|
||||
val pushReminderTime = useDataStoreValueBlocking(NOTICE_REMINDER_TIME)
|
||||
val forceShowNotice = useDataStoreValue(FORCE_SHOW_NOTICE)
|
||||
val isAlreadyPaid = useDataStoreValue(IS_ALREADY_PAID)
|
||||
val pushReminderTime = useDataStoreValue(NOTICE_REMINDER_TIME)
|
||||
val currentTime = System.currentTimeMillis() / 1000L
|
||||
|
||||
val isDisplayingMigrationNotice = !useDataStoreValueBlocking(dismissedMigrateUpdateNotice)
|
||||
val isDisplayingMigrationNotice = !useDataStoreValue(dismissedMigrateUpdateNotice)
|
||||
|
||||
val reminderTimeIsUp = (currentTime >= pushReminderTime)
|
||||
|
||||
|
@ -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.useDataStoreValueBlocking
|
||||
import org.futo.inputmethod.latin.uix.settings.useDataStoreValue
|
||||
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 = useDataStoreValueBlocking(THEME_KEY.key, THEME_KEY.default)
|
||||
val themeIdx = useDataStoreValue(THEME_KEY)
|
||||
|
||||
val theme: ThemeOption = themeIdx?.let { ThemeOptions[it].ensureAvailable(context) }
|
||||
?: VoiceInputTheme
|
||||
|
Loading…
Reference in New Issue
Block a user