Use an explicit SCHEMA_VERSION instead of BuildConfig.VERSION_CODE (#3324)

* Use an explicit SCHEMA_VERSION instead of BuildConfig.VERSION_CODE

Every nightly release has a new BuildConfig.VERSION_CODE, so the previous
code would not do the right thing.

Require the schema version to be explicitly set. While I'm here, provide
a clear set of guidelines as to what has to happen when the schema changes.

* Improve documentation links
This commit is contained in:
Nik Clayton 2023-02-25 21:22:49 +01:00 committed by GitHub
commit fda8c80949
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View file

@ -23,6 +23,7 @@ import autodispose2.AutoDisposePlugins
import com.keylesspalace.tusky.components.notifications.NotificationWorkerFactory
import com.keylesspalace.tusky.di.AppInjector
import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.settings.SCHEMA_VERSION
import com.keylesspalace.tusky.util.APP_THEME_DEFAULT
import com.keylesspalace.tusky.util.LocaleManager
import com.keylesspalace.tusky.util.setAppNightMode
@ -69,10 +70,10 @@ 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 97, so that's the default.
val oldVersion = sharedPreferences.getInt(PrefKeys.SCHEMA_VERSION, 97)
if (oldVersion != BuildConfig.VERSION_CODE) {
upgradeSharedPreferences(oldVersion, BuildConfig.VERSION_CODE)
// version that did not have a SCHEMA_VERSION was 100, so that's the default.
val oldVersion = sharedPreferences.getInt(PrefKeys.SCHEMA_VERSION, 100)
if (oldVersion != SCHEMA_VERSION) {
upgradeSharedPreferences(oldVersion, SCHEMA_VERSION)
}
// In this case, we want to have the emoji preferences merged with the other ones