From a16240f123d3040bcfc12ba68cab77616a827898 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 24 Mar 2021 09:27:00 -0400 Subject: [PATCH] Show unread entries first when sorting by unread (closes #4711) Based on https://github.com/Jays2Kings/tachiyomiJ2K/commit/b212f8233e2d3ceffaddc5fcd1ef884e137dae2a --- .../kanade/tachiyomi/ui/library/LibraryPresenter.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 0f678b8e2..4f3cf065f 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 @@ -236,6 +236,7 @@ class LibraryPresenter( db.getLatestChapterManga().executeAsBlocking().associate { it.id!! to counter++ } } + val sortAscending = preferences.librarySortingAscending().get() val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 -> when (sortingMode) { LibrarySort.ALPHA -> i1.manga.title.compareTo(i2.manga.title, true) @@ -246,7 +247,13 @@ class LibraryPresenter( manga1LastRead.compareTo(manga2LastRead) } LibrarySort.LAST_CHECKED -> i2.manga.last_update.compareTo(i1.manga.last_update) - LibrarySort.UNREAD -> i1.manga.unread.compareTo(i2.manga.unread) + LibrarySort.UNREAD -> when { + // Ensure unread content comes first + i1.manga.unread == i2.manga.unread -> 0 + i1.manga.unread == 0 -> if (sortAscending) 1 else -1 + i2.manga.unread == 0 -> if (sortAscending) -1 else 1 + else -> i1.manga.unread.compareTo(i2.manga.unread) + } LibrarySort.TOTAL -> { val manga1TotalChapter = totalChapterManga[i1.manga.id!!] ?: 0 val mange2TotalChapter = totalChapterManga[i2.manga.id!!] ?: 0 @@ -264,7 +271,7 @@ class LibraryPresenter( } } - val comparator = if (preferences.librarySortingAscending().get()) { + val comparator = if (sortAscending) { Comparator(sortFn) } else { Collections.reverseOrder(sortFn)