From b63578974054c76b62e543bf9f7c7b08b6be5211 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 10 Jun 2022 09:49:50 -0400 Subject: [PATCH] Actually compare chapter numbers as numbers when sorting (fixes #7247) (cherry picked from commit da8669c826e6575a76751842bda3da59dc2f07c7) --- .../ui/browse/migration/MigrationFlags.kt | 32 +++++++++---------- .../tachiyomi/util/chapter/ChapterSorter.kt | 7 ++-- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt index a6307bcf2..649c48d21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/migration/MigrationFlags.kt @@ -20,8 +20,8 @@ object MigrationFlags { private const val CATEGORIES2 = 0x2 private const val TRACK2 = 0x4 - private val coverCache: CoverCache by injectLazy() - private val db: DatabaseHelper = Injekt.get() + private val coverCache: CoverCache by injectLazy() + private val db: DatabaseHelper = Injekt.get() val flags get() = arrayOf(CHAPTERS, CATEGORIES, TRACK, CUSTOM_COVER) @@ -49,19 +49,19 @@ object MigrationFlags { return positions.fold(0) { accumulated, position -> accumulated or (1 shl position) } } - fun titles(manga: Manga?): Array { - val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() - if (manga != null) { - db.inTransaction { - if (db.getTracks(manga).executeAsBlocking().isNotEmpty()) { - titles.add(R.string.track) - } + fun titles(manga: Manga?): Array { + val titles = arrayOf(R.string.chapters, R.string.categories).toMutableList() + if (manga != null) { + db.inTransaction { + if (db.getTracks(manga).executeAsBlocking().isNotEmpty()) { + titles.add(R.string.track) + } - if (manga.hasCustomCover(coverCache)) { - titles.add(R.string.custom_cover) - } - } - } - return titles.toTypedArray() - } + if (manga.hasCustomCover(coverCache)) { + titles.add(R.string.custom_cover) + } + } + } + return titles.toTypedArray() + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt index 764f00491..a069a2c7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/chapter/ChapterSorter.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.util.chapter import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder fun getChapterSort(manga: Manga, sortDescending: Boolean = manga.sortDescending()): (Chapter, Chapter) -> Int { return when (manga.sorting) { @@ -11,13 +10,13 @@ fun getChapterSort(manga: Manga, sortDescending: Boolean = manga.sortDescending( false -> { c1, c2 -> c2.source_order.compareTo(c1.source_order) } } Manga.CHAPTER_SORTING_NUMBER -> when (sortDescending) { - true -> { c1, c2 -> c2.chapter_number.toString().compareToCaseInsensitiveNaturalOrder(c1.chapter_number.toString()) } - false -> { c1, c2 -> c1.chapter_number.toString().compareToCaseInsensitiveNaturalOrder(c2.chapter_number.toString()) } + true -> { c1, c2 -> c2.chapter_number.compareTo(c1.chapter_number) } + false -> { c1, c2 -> c1.chapter_number.compareTo(c2.chapter_number) } } Manga.CHAPTER_SORTING_UPLOAD_DATE -> when (sortDescending) { true -> { c1, c2 -> c2.date_upload.compareTo(c1.date_upload) } false -> { c1, c2 -> c1.date_upload.compareTo(c2.date_upload) } } - else -> throw NotImplementedError("Unimplemented sorting method") + else -> throw NotImplementedError("Invalid chapter sorting method: ${manga.sorting}") } }