3204: Add an account based preference store (#3205)

* 3204: Add an account based preference store

* 3204: (related) reformat a bit, add todo

* 3204: Use the preference data store for all three account settings

* 3204: Move event handling to account settings handler

* 3204: Correct includes

* 3204: Appease linter

* 3204: Appease linter again

* 3204: Add an account based preference store

* 3204: Use the preference data store for all three account settings

* 3204: Move event handling to account settings handler

* 3204: Correct includes

* 3204: Add general "preference upgrade loop stepper"; use it for removing obsolete account settings (in shared)

* 3204: Add missing spaces

* 3204: Key is non-nullable

* 3204: Upgrade to new settings migration code

* 3204: Remove (commented) DI code
This commit is contained in:
UlrichKu 2023-02-27 14:07:28 +01:00 committed by GitHub
commit b4d10c9613
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 45 deletions

View file

@ -69,9 +69,8 @@ class TuskyApplication : Application(), HasAndroidInjector {
AppInjector.init(this)
// Migrate shared preference keys and defaults from version to version. The last
// version that did not have a SCHEMA_VERSION was 100, so that's the default.
val oldVersion = sharedPreferences.getInt(PrefKeys.SCHEMA_VERSION, 100)
// Migrate shared preference keys and defaults from version to version.
val oldVersion = sharedPreferences.getInt(PrefKeys.SCHEMA_VERSION, 0)
if (oldVersion != SCHEMA_VERSION) {
upgradeSharedPreferences(oldVersion, SCHEMA_VERSION)
}
@ -105,7 +104,13 @@ class TuskyApplication : Application(), HasAndroidInjector {
Log.d(TAG, "Upgrading shared preferences: $oldVersion -> $newVersion")
val editor = sharedPreferences.edit()
// Future upgrade code goes here
if (oldVersion < 2023022701) {
// These preferences are (now) handled in AccountPreferenceHandler. Remove them from shared for clarity.
editor.remove(PrefKeys.ALWAYS_OPEN_SPOILER)
editor.remove(PrefKeys.ALWAYS_SHOW_SENSITIVE_MEDIA)
editor.remove(PrefKeys.MEDIA_PREVIEW_ENABLED)
}
editor.putInt(PrefKeys.SCHEMA_VERSION, newVersion)
editor.apply()