mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-19 13:49:13 +00:00
use the context.prefs shortcut
This commit is contained in:
parent
52e0e891fe
commit
07cac44861
4 changed files with 9 additions and 11 deletions
|
@ -35,7 +35,6 @@ import androidx.compose.ui.text.style.TextAlign
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.settings.dialogs.SliderDialog
|
||||
|
||||
|
@ -140,7 +139,7 @@ fun SwitchPreference(
|
|||
onCheckedChange: (Boolean) -> Unit = { },
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(ctx)
|
||||
val prefs = ctx.prefs()
|
||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
||||
if (b?.value ?: 0 < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
|
@ -198,7 +197,7 @@ fun <T: Number> SliderPreference(
|
|||
onValueChanged: (Float) -> Unit = { },
|
||||
) {
|
||||
val ctx = LocalContext.current
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(ctx)
|
||||
val prefs = ctx.prefs()
|
||||
val b = (ctx.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
||||
if (b?.value ?: 0 < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
|
|
|
@ -10,7 +10,6 @@ import androidx.compose.ui.platform.ComposeView
|
|||
import androidx.core.view.isGone
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
|
||||
// todo
|
||||
|
@ -78,7 +77,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
// meh, and using a TextField adds another 300 kb... huge chunks for sth that seems so small
|
||||
|
||||
class SettingsActivity2 : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private val prefs by lazy { DeviceProtectedUtils.getSharedPreferences(this) }
|
||||
private val prefs by lazy { this.prefs() }
|
||||
val prefChanged = MutableStateFlow(0) // simple counter, as the only relevant information is that something changed
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -25,7 +25,6 @@ import androidx.core.net.toUri
|
|||
import helium314.keyboard.latin.BuildConfig
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.DebugSettings
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.latin.utils.SpannableStringUtils
|
||||
import helium314.keyboard.settings.AllPrefs
|
||||
|
@ -36,6 +35,7 @@ import helium314.keyboard.settings.SearchPrefScreen
|
|||
import helium314.keyboard.settings.SettingsActivity2
|
||||
import helium314.keyboard.settings.Theme
|
||||
import helium314.keyboard.settings.getActivity
|
||||
import helium314.keyboard.settings.prefs
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -68,7 +68,7 @@ fun createAboutPrefs(context: Context) = listOf(
|
|||
PrefDef(context, NonSettingsPrefs.VERSION, R.string.version) {
|
||||
var count by rememberSaveable { mutableIntStateOf(0) }
|
||||
val ctx = LocalContext.current
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(ctx)
|
||||
val prefs = ctx.prefs()
|
||||
Preference(
|
||||
name = it.title,
|
||||
description = stringResource(R.string.version_text, BuildConfig.VERSION_NAME),
|
||||
|
|
|
@ -23,7 +23,6 @@ import helium314.keyboard.latin.R
|
|||
import helium314.keyboard.latin.permissions.PermissionsUtil
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
import helium314.keyboard.latin.settings.UserDictionaryListFragment
|
||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||
import helium314.keyboard.latin.utils.Log
|
||||
import helium314.keyboard.settings.AllPrefs
|
||||
import helium314.keyboard.settings.NonSettingsPrefs
|
||||
|
@ -37,13 +36,14 @@ import helium314.keyboard.settings.Theme
|
|||
import helium314.keyboard.settings.dialogs.ConfirmationDialog
|
||||
import helium314.keyboard.settings.dialogs.ListPickerDialog
|
||||
import helium314.keyboard.settings.getActivity
|
||||
import helium314.keyboard.settings.prefs
|
||||
import helium314.keyboard.settings.themeChanged
|
||||
|
||||
@Composable
|
||||
fun TextCorrectionScreen(
|
||||
onClickBack: () -> Unit,
|
||||
) {
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(LocalContext.current)
|
||||
val prefs = LocalContext.current.prefs()
|
||||
val b = (LocalContext.current.getActivity() as? SettingsActivity2)?.prefChanged?.collectAsState()
|
||||
if (b?.value ?: 0 < 0)
|
||||
Log.v("irrelevant", "stupid way to trigger recomposition on preference change")
|
||||
|
@ -137,7 +137,7 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
|||
stringResource(R.string.auto_correction_threshold_mode_aggressive) to "1",
|
||||
stringResource(R.string.auto_correction_threshold_mode_very_aggressive) to "2",
|
||||
)
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(LocalContext.current)
|
||||
val prefs = LocalContext.current.prefs()
|
||||
val selected = items.firstOrNull { it.second == prefs.getString(def.key, "0") }
|
||||
Preference(
|
||||
name = def.title,
|
||||
|
@ -208,7 +208,7 @@ fun createCorrectionPrefs(context: Context) = listOf(
|
|||
}
|
||||
)
|
||||
if (showConfirmDialog) {
|
||||
val prefs = DeviceProtectedUtils.getSharedPreferences(LocalContext.current)
|
||||
val prefs = LocalContext.current.prefs()
|
||||
ConfirmationDialog(
|
||||
onDismissRequest = { showConfirmDialog = false },
|
||||
onConfirmed = {
|
||||
|
|
Loading…
Add table
Reference in a new issue