Skip to content

Commit 7ab366f

Browse files
committed
refactor(Preferences): use MIGRATION length as version
Uses the `MIGRATION` length to determine the appropriate migrations to be run. This works, as opposed to Room migrations, there is no `AutoMigration`, i.e. no version increase without a corresponding `PreferenceMigration`. By automatically determining the preference version, we avoid issues, where a new migration is created, but never actually run, as the version is not incremented. Ref: libre-tube@c746647
1 parent b908dbd commit 7ab366f

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

app/src/main/java/com/github/libretube/helpers/PreferenceHelper.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ object PreferenceHelper {
3535
*/
3636
private const val USER_ID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
3737

38-
39-
/**
40-
* Current version of the preferences.
41-
*/
42-
private const val PREFERENCE_VERSION = 1
43-
4438
/**
45-
* Migrations required to migrate the application to a newer [PREFERENCE_VERSION].
39+
* Migrations required to migrate the application to a newer preference version.
40+
* The version is automatically determined from the number of migrations available.
4641
*/
47-
private val MIGRATIONS = listOf(
42+
private val MIGRATIONS = arrayOf(
4843
PreferenceMigration(0, 1) {
4944
LibreTubeApp.instance.resources
5045
.getStringArray(R.array.sponsorBlockSegments)
@@ -68,13 +63,11 @@ object PreferenceHelper {
6863

6964
/**
7065
* Migrate preference to a new version.
71-
*
72-
* Migrations are run up to [PREFERENCE_VERSION].
7366
*/
7467
fun migrate() {
7568
var currentPrefVersion = getInt(PreferenceKeys.PREFERENCE_VERSION, 0)
7669

77-
while (currentPrefVersion < PREFERENCE_VERSION) {
70+
while (currentPrefVersion < MIGRATIONS.count()) {
7871
val next = currentPrefVersion + 1
7972

8073
val migration =

0 commit comments

Comments
 (0)