diff --git a/app/src/main/java/helium314/keyboard/settings/Preference.kt b/app/src/main/java/helium314/keyboard/settings/Preference.kt index 31b8e6fd..77427bac 100644 --- a/app/src/main/java/helium314/keyboard/settings/Preference.kt +++ b/app/src/main/java/helium314/keyboard/settings/Preference.kt @@ -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 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") diff --git a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt index 6b8bc2c8..e55f4c09 100644 --- a/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt +++ b/app/src/main/java/helium314/keyboard/settings/SettingsActivity.kt @@ -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?) { diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt index bcc52951..48f74413 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt @@ -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), diff --git a/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt index 9cf64851..c63da141 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/TextCorrectionScreen.kt @@ -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 = {