From dd8cab456286eb2d208f8f50ed087a3ef69e1271 Mon Sep 17 00:00:00 2001 From: paronos Date: Sat, 4 Feb 2017 12:03:54 +0100 Subject: [PATCH] improve local manga chapter sorting (#672) --- .../main/java/eu/kanade/tachiyomi/source/LocalSource.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 93b59f454..2cdbfdefd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -60,6 +60,7 @@ class LocalSource(private val context: Context) : CatalogueSource { override fun fetchMangaDetails(manga: SManga) = Observable.just(manga) override fun fetchChapterList(manga: SManga): Observable> { + val comparator = CaseInsensitiveSimpleNaturalComparator.getInstance() val chapters = getBaseDirectories(context) .mapNotNull { File(it, manga.url).listFiles()?.toList() } .flatten() @@ -72,13 +73,16 @@ class LocalSource(private val context: Context) : CatalogueSource { } else { chapterFile.nameWithoutExtension } - val chapNameCut = chapName.replace(manga.title, "", true) + val chapNameCut = chapName.replace(manga.title, "", true).trim() name = if (chapNameCut.isEmpty()) chapName else chapNameCut date_upload = chapterFile.lastModified() ChapterRecognition.parseChapterNumber(this, manga) } } - .sortedByDescending { it.chapter_number } + .sortedWith(Comparator { c1, c2 -> + val c = c2.chapter_number.compareTo(c1.chapter_number) + if (c == 0) comparator.compare(c2.name, c1.name) else c + }) return Observable.just(chapters) }