From fd407b2b038af1cc5b68ce6736528625c078a0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 22 Oct 2022 12:31:40 +0200 Subject: [PATCH] [Config] Set highest data version by default. --- .../java/pl/szczodrzynski/edziennik/config/Config.kt | 5 +++-- .../pl/szczodrzynski/edziennik/config/ProfileConfig.kt | 2 +- .../edziennik/config/utils/AppConfigMigrationV3.kt | 10 +++------- .../edziennik/config/utils/ConfigMigration.kt | 10 ++++++---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt index f065a97e..4da4180e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/Config.kt @@ -24,7 +24,7 @@ class Config(db: AppDb) : BaseConfig(db) { val timetable by lazy { ConfigTimetable(this) } val grades by lazy { ConfigGrades(this) } - var dataVersion by config(0) + var dataVersion by config(DATA_VERSION) var hash by config("") var lastProfileId by config(0) @@ -49,7 +49,8 @@ class Config(db: AppDb) : BaseConfig(db) { var widgetConfigs by config { JsonObject() } fun migrate(app: App) { - if (dataVersion < DATA_VERSION) + if (dataVersion < DATA_VERSION || hash == "") + // migrate old data version OR freshly installed app (or updated from 3.x) ConfigMigration(app, this) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfig.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfig.kt index f97c6892..502f0cd6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfig.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfig.kt @@ -26,7 +26,7 @@ class ProfileConfig( val timetable by lazy { ConfigTimetable(this) } val grades by lazy { ConfigGrades(this) }*/ - var dataVersion by config(0) + var dataVersion by config(DATA_VERSION) var hash by config("") init { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/AppConfigMigrationV3.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/AppConfigMigrationV3.kt index 5af5e1b8..d99de89d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/AppConfigMigrationV3.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/AppConfigMigrationV3.kt @@ -16,9 +16,9 @@ import pl.szczodrzynski.edziennik.utils.models.Time import kotlin.math.abs class AppConfigMigrationV3(p: SharedPreferences, config: Config) { - init { config.apply { + init { val s = "app.appConfig" - if (dataVersion < 1) { + config.apply { ui.theme = p.getString("$s.appTheme", null)?.toIntOrNull() ?: 1 sync.enabled = p.getString("$s.registerSyncEnabled", null)?.toBoolean() ?: true sync.interval = p.getString("$s.registerSyncInterval", null)?.toIntOrNull() ?: 3600 @@ -37,9 +37,6 @@ class AppConfigMigrationV3(p: SharedPreferences, config: Config) { NavTarget.HOMEWORK, NavTarget.SETTINGS ) - dataVersion = 1 - } - if (dataVersion < 2) { devModePassword = p.getString("$s.devModePassword", null).fix() sync.tokenApp = p.getString("$s.fcmToken", null).fix() timetable.bellSyncMultiplier = p.getString("$s.bellSyncMultiplier", null)?.toIntOrNull() ?: 0 @@ -86,9 +83,8 @@ class AppConfigMigrationV3(p: SharedPreferences, config: Config) { LoginType.LIBRUS.id -> sync.tokenLibrus = token } } - dataVersion = 2 } - }} + } private fun String?.fix(): String? { return this?.replace("\"", "")?.let { if (it == "null") null else it } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt index cbd18e0c..f44d6e56 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/utils/ConfigMigration.kt @@ -5,12 +5,9 @@ package pl.szczodrzynski.edziennik.config.utils import android.content.Context +import androidx.core.content.edit import pl.szczodrzynski.edziennik.App -import pl.szczodrzynski.edziennik.BuildConfig import pl.szczodrzynski.edziennik.config.Config -import pl.szczodrzynski.edziennik.ext.HOUR -import pl.szczodrzynski.edziennik.ui.base.enums.NavTarget -import pl.szczodrzynski.edziennik.utils.managers.GradesManager.Companion.ORDER_BY_DATE_DESC import pl.szczodrzynski.edziennik.utils.models.Time import kotlin.math.abs @@ -22,6 +19,9 @@ class ConfigMigration(app: App, config: Config) { // migrate appConfig from app version 3.x and lower. // Updates dataVersion to level 2. AppConfigMigrationV3(p, config) + p.edit { + remove("app.appConfig.appTheme") + } } if (dataVersion < 11) { @@ -43,5 +43,7 @@ class ConfigMigration(app: App, config: Config) { dataVersion = 11 } + + hash = "invalid" }} }