From 681e9396b3f9baf9c6f0e66f596830c662dbadb9 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 7 May 2022 23:48:53 -0400 Subject: [PATCH] Fix crash when using renamed library sort methods (fixes #7092) --- app/build.gradle.kts | 2 +- .../main/java/eu/kanade/tachiyomi/Migrations.kt | 17 ++++++++++++++--- .../tachiyomi/ui/library/LibraryPresenter.kt | 1 + .../ui/library/setting/SortModeSetting.kt | 12 +++++++++++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 24ea960b0..f5809ba5f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,7 +25,7 @@ android { applicationId = "eu.kanade.tachiyomi" minSdk = AndroidConfig.minSdk targetSdk = AndroidConfig.targetSdk - versionCode = 80 + versionCode = 81 versionName = "0.13.4" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 0674fc243..c17493a63 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -204,11 +204,11 @@ object Migrations { val newSortingMode = when (oldSortingMode) { LibrarySort.ALPHA -> SortModeSetting.ALPHABETICAL LibrarySort.LAST_READ -> SortModeSetting.LAST_READ - LibrarySort.LAST_CHECKED -> SortModeSetting.LAST_MANGA_UPDATE - LibrarySort.UNREAD -> SortModeSetting.UNREAD_COUNT + LibrarySort.LAST_CHECKED -> SortModeSetting.LAST_CHECKED + LibrarySort.UNREAD -> SortModeSetting.UNREAD LibrarySort.TOTAL -> SortModeSetting.TOTAL_CHAPTERS LibrarySort.LATEST_CHAPTER -> SortModeSetting.LATEST_CHAPTER - LibrarySort.CHAPTER_FETCH_DATE -> SortModeSetting.CHAPTER_FETCH_DATE + LibrarySort.CHAPTER_FETCH_DATE -> SortModeSetting.DATE_FETCHED LibrarySort.DATE_ADDED -> SortModeSetting.DATE_ADDED else -> SortModeSetting.ALPHABETICAL } @@ -266,6 +266,17 @@ object Migrations { preferences.navigationModeWebtoon().set(5) } } + if (oldVersion < 81) { + // Handle renamed enum values + @Suppress("DEPRECATION") + val newSortingMode = when (val oldSortingMode = preferences.librarySortingMode().get()) { + SortModeSetting.LAST_CHECKED -> SortModeSetting.LAST_MANGA_UPDATE + SortModeSetting.UNREAD -> SortModeSetting.UNREAD_COUNT + SortModeSetting.DATE_FETCHED -> SortModeSetting.CHAPTER_FETCH_DATE + else -> oldSortingMode + } + preferences.librarySortingMode().set(newSortingMode) + } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 41acf2175..7e3fa73c4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -318,6 +318,7 @@ class LibraryPresenter( SortModeSetting.DATE_ADDED -> { i1.manga.date_added.compareTo(i2.manga.date_added) } + else -> throw IllegalStateException("Invalid SortModeSetting: $sortingMode") } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/SortModeSetting.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/SortModeSetting.kt index 8a0a75860..d7fe8a16f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/SortModeSetting.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/setting/SortModeSetting.kt @@ -11,7 +11,17 @@ enum class SortModeSetting(val flag: Int) { TOTAL_CHAPTERS(0b00010000), LATEST_CHAPTER(0b00010100), CHAPTER_FETCH_DATE(0b00011000), - DATE_ADDED(0b00011100); + DATE_ADDED(0b00011100), + + @Deprecated("Use LAST_MANGA_UPDATE") + LAST_CHECKED(0b00001000), + + @Deprecated("Use UNREAD_COUNT") + UNREAD(0b00001100), + + @Deprecated("Use CHAPTER_FETCH_DATE") + DATE_FETCHED(0b00011000), + ; companion object { // Mask supports for more sorting flags if necessary