Sorting for library now honors skipping articles in other sorting modes

This commit is contained in:
Jay 2020-01-14 22:19:33 -08:00
parent 3e04619404
commit f42eb88076

View File

@ -208,24 +208,23 @@ class LibraryPresenter(
listOf(default) + db.getCategories().executeAsBlocking()
}
val ascending = preferences.librarySortingAscending().getOrDefault()
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
when (sortingMode) {
val compare = when (sortingMode) {
LibrarySort.ALPHA -> sortAlphabetical(i1, i2)
LibrarySort.LAST_READ -> {
// Get index of manga, set equal to list if size unknown.
val manga1LastRead = lastReadManga[i1.manga.id!!] ?: lastReadManga.size
val manga2LastRead = lastReadManga[i2.manga.id!!] ?: lastReadManga.size
val mangaCompare = manga1LastRead.compareTo(manga2LastRead)
if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare
manga1LastRead.compareTo(manga2LastRead)
}
LibrarySort.LAST_UPDATED -> i2.manga.last_update.compareTo(i1.manga.last_update)
LibrarySort.UNREAD -> i1.manga.unread.compareTo(i2.manga.unread)
LibrarySort.TOTAL -> {
val manga1TotalChapter = totalChapterManga[i1.manga.id!!] ?: 0
val mange2TotalChapter = totalChapterManga[i2.manga.id!!] ?: 0
val mangaCompare = manga1TotalChapter.compareTo(mange2TotalChapter)
if (mangaCompare == 0) sortAlphabetical(i1, i2) else mangaCompare
manga1TotalChapter.compareTo(mange2TotalChapter)
}
LibrarySort.DRAG_AND_DROP -> {
if (i1.manga.category == i2.manga.category) {
@ -258,9 +257,14 @@ class LibraryPresenter(
}
else -> 0
}
if (compare == 0) {
if (ascending) sortAlphabetical(i1, i2)
else sortAlphabetical(i2, i1)
}
else compare
}
val comparator = if (preferences.librarySortingAscending().getOrDefault())
val comparator = if (ascending)
Comparator(sortFn)
else
Collections.reverseOrder(sortFn)