mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 05:01:52 +01:00
improve local manga chapter sorting (#672)
This commit is contained in:
parent
f7c791d153
commit
dd8cab4562
@ -60,6 +60,7 @@ class LocalSource(private val context: Context) : CatalogueSource {
|
|||||||
override fun fetchMangaDetails(manga: SManga) = Observable.just(manga)
|
override fun fetchMangaDetails(manga: SManga) = Observable.just(manga)
|
||||||
|
|
||||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
||||||
|
val comparator = CaseInsensitiveSimpleNaturalComparator.getInstance<String>()
|
||||||
val chapters = getBaseDirectories(context)
|
val chapters = getBaseDirectories(context)
|
||||||
.mapNotNull { File(it, manga.url).listFiles()?.toList() }
|
.mapNotNull { File(it, manga.url).listFiles()?.toList() }
|
||||||
.flatten()
|
.flatten()
|
||||||
@ -72,13 +73,16 @@ class LocalSource(private val context: Context) : CatalogueSource {
|
|||||||
} else {
|
} else {
|
||||||
chapterFile.nameWithoutExtension
|
chapterFile.nameWithoutExtension
|
||||||
}
|
}
|
||||||
val chapNameCut = chapName.replace(manga.title, "", true)
|
val chapNameCut = chapName.replace(manga.title, "", true).trim()
|
||||||
name = if (chapNameCut.isEmpty()) chapName else chapNameCut
|
name = if (chapNameCut.isEmpty()) chapName else chapNameCut
|
||||||
date_upload = chapterFile.lastModified()
|
date_upload = chapterFile.lastModified()
|
||||||
ChapterRecognition.parseChapterNumber(this, manga)
|
ChapterRecognition.parseChapterNumber(this, manga)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sortedByDescending { it.chapter_number }
|
.sortedWith(Comparator<SChapter> { 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)
|
return Observable.just(chapters)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user