forked from github/szkolny
[Config] Set highest data version by default.
This commit is contained in:
parent
40ed5a221f
commit
fd407b2b03
@ -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<Int>(0)
|
||||
var dataVersion by config<Int>(DATA_VERSION)
|
||||
var hash by config<String>("")
|
||||
|
||||
var lastProfileId by config<Int>(0)
|
||||
@ -49,7 +49,8 @@ class Config(db: AppDb) : BaseConfig(db) {
|
||||
var widgetConfigs by config<JsonObject> { 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)
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ class ProfileConfig(
|
||||
val timetable by lazy { ConfigTimetable(this) }
|
||||
val grades by lazy { ConfigGrades(this) }*/
|
||||
|
||||
var dataVersion by config<Int>(0)
|
||||
var dataVersion by config<Int>(DATA_VERSION)
|
||||
var hash by config<String>("")
|
||||
|
||||
init {
|
||||
|
@ -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 }
|
||||
|
@ -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"
|
||||
}}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user