Fix downloaded badges appearing when filtering by downloaded

Fixes #8850

(cherry picked from commit c4c6e41c46f38602578af9b0fa36c037482252da)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryScreenModel.kt
This commit is contained in:
arkon 2023-01-07 10:32:14 -05:00 committed by Jobobby04
parent 65c95fbb78
commit 895cdad7ca

View File

@ -158,7 +158,10 @@ class LibraryScreenModel(
state.map { it.searchQuery }.distinctUntilChanged(), state.map { it.searchQuery }.distinctUntilChanged(),
getLibraryFlow(), getLibraryFlow(),
getTracksPerManga.subscribe(), getTracksPerManga.subscribe(),
getTrackingFilterFlow(), combine(
getTrackingFilterFlow(),
downloadCache.changes,
) { a, b -> a to b },
// SY --> // SY -->
combine( combine(
state.map { it.groupType }.distinctUntilChanged(), state.map { it.groupType }.distinctUntilChanged(),
@ -168,7 +171,7 @@ class LibraryScreenModel(
Triple(a, b, c) Triple(a, b, c)
}, },
// SY <-- // SY <--
) { searchQuery, library, tracks, loggedInTrackServices, (groupType, displayMode, sort) -> ) { searchQuery, library, tracks, (loggedInTrackServices, _), (groupType, displayMode, sort) ->
library library
// SY --> // SY -->
.applyGrouping(groupType, displayMode) .applyGrouping(groupType, displayMode)
@ -284,14 +287,12 @@ class LibraryScreenModel(
val filterLewd = prefs.filterLewd val filterLewd = prefs.filterLewd
// SY <-- // SY <--
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item -> val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{
if (!downloadedOnly && filterDownloaded == TriStateGroup.State.IGNORE.value) return@downloaded true if (!downloadedOnly && filterDownloaded == TriStateGroup.State.IGNORE.value) return@downloaded true
val isDownloaded = when {
item.libraryManga.manga.isLocal() -> true
item.downloadCount != -1L -> item.downloadCount > 0
else -> downloadManager.getDownloadCount(item.libraryManga.manga) > 0
}
val isDownloaded = it.libraryManga.manga.isLocal() ||
it.downloadCount > 0 ||
downloadManager.getDownloadCount(it.libraryManga.manga) > 0
return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.INCLUDE.value) { return@downloaded if (downloadedOnly || filterDownloaded == TriStateGroup.State.INCLUDE.value) {
isDownloaded isDownloaded
} else { } else {
@ -299,10 +300,10 @@ class LibraryScreenModel(
} }
} }
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item -> val filterFnUnread: (LibraryItem) -> Boolean = unread@{
if (filterUnread == TriStateGroup.State.IGNORE.value) return@unread true if (filterUnread == TriStateGroup.State.IGNORE.value) return@unread true
val isUnread = item.libraryManga.unreadCount > 0
val isUnread = it.libraryManga.unreadCount > 0
return@unread if (filterUnread == TriStateGroup.State.INCLUDE.value) { return@unread if (filterUnread == TriStateGroup.State.INCLUDE.value) {
isUnread isUnread
} else { } else {
@ -310,10 +311,10 @@ class LibraryScreenModel(
} }
} }
val filterFnStarted: (LibraryItem) -> Boolean = started@{ item -> val filterFnStarted: (LibraryItem) -> Boolean = started@{
if (filterStarted == TriStateGroup.State.IGNORE.value) return@started true if (filterStarted == TriStateGroup.State.IGNORE.value) return@started true
val hasStarted = item.libraryManga.hasStarted
val hasStarted = it.libraryManga.hasStarted
return@started if (filterStarted == TriStateGroup.State.INCLUDE.value) { return@started if (filterStarted == TriStateGroup.State.INCLUDE.value) {
hasStarted hasStarted
} else { } else {
@ -321,11 +322,10 @@ class LibraryScreenModel(
} }
} }
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item -> val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{
if (filterBookmarked == TriStateGroup.State.IGNORE.value) return@bookmarked true if (filterBookmarked == TriStateGroup.State.IGNORE.value) return@bookmarked true
val hasBookmarks = item.libraryManga.hasBookmarks val hasBookmarks = it.libraryManga.hasBookmarks
return@bookmarked if (filterBookmarked == TriStateGroup.State.INCLUDE.value) { return@bookmarked if (filterBookmarked == TriStateGroup.State.INCLUDE.value) {
hasBookmarks hasBookmarks
} else { } else {
@ -333,10 +333,10 @@ class LibraryScreenModel(
} }
} }
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item -> val filterFnCompleted: (LibraryItem) -> Boolean = completed@{
if (filterCompleted == TriStateGroup.State.IGNORE.value) return@completed true if (filterCompleted == TriStateGroup.State.IGNORE.value) return@completed true
val isCompleted = item.libraryManga.manga.status.toInt() == SManga.COMPLETED
val isCompleted = it.libraryManga.manga.status.toInt() == SManga.COMPLETED
return@completed if (filterCompleted == TriStateGroup.State.INCLUDE.value) { return@completed if (filterCompleted == TriStateGroup.State.INCLUDE.value) {
isCompleted isCompleted
} else { } else {
@ -365,9 +365,9 @@ class LibraryScreenModel(
} }
// SY --> // SY -->
val filterFnLewd: (LibraryItem) -> Boolean = lewd@{ item -> val filterFnLewd: (LibraryItem) -> Boolean = lewd@{
if (filterLewd == TriStateGroup.State.IGNORE.value) return@lewd true if (filterLewd == TriStateGroup.State.IGNORE.value) return@lewd true
val isLewd = item.libraryManga.manga.isLewd() val isLewd = it.libraryManga.manga.isLewd()
return@lewd if (filterLewd == TriStateGroup.State.INCLUDE.value) { return@lewd if (filterLewd == TriStateGroup.State.INCLUDE.value) {
isLewd isLewd
@ -377,16 +377,16 @@ class LibraryScreenModel(
} }
// SY <-- // SY <--
val filterFn: (LibraryItem) -> Boolean = filter@{ item -> val filterFn: (LibraryItem) -> Boolean = filter@{
return@filter !( return@filter !(
!filterFnDownloaded(item) || !filterFnDownloaded(it) ||
!filterFnUnread(item) || !filterFnUnread(it) ||
!filterFnStarted(item) || !filterFnStarted(it) ||
!filterFnBookmarked(item) || !filterFnBookmarked(it) ||
!filterFnCompleted(item) || !filterFnCompleted(it) ||
!filterFnTracking(item) || !filterFnTracking(it) ||
// SY --> // SY -->
!filterFnLewd(item) !filterFnLewd(it)
// SY <-- // SY <--
) )
} }
@ -515,8 +515,6 @@ class LibraryScreenModel(
/** /**
* Get the categories and all its manga from the database. * Get the categories and all its manga from the database.
*
* @return an observable of the categories and its manga.
*/ */
private fun getLibraryFlow(): Flow<LibraryMap> { private fun getLibraryFlow(): Flow<LibraryMap> {
val libraryMangasFlow = combine( val libraryMangasFlow = combine(
@ -526,13 +524,9 @@ class LibraryScreenModel(
) { libraryMangaList, prefs, _ -> ) { libraryMangaList, prefs, _ ->
libraryMangaList libraryMangaList
.map { libraryManga -> .map { libraryManga ->
val needsDownloadCounts = prefs.downloadBadge ||
prefs.filterDownloaded != TriStateGroup.State.IGNORE.value ||
prefs.globalFilterDownloaded
// Display mode based on user preference: take it from global library setting or category // Display mode based on user preference: take it from global library setting or category
LibraryItem(libraryManga).apply { LibraryItem(libraryManga).apply {
downloadCount = if (needsDownloadCounts) { downloadCount = if (prefs.downloadBadge) {
// SY --> // SY -->
if (libraryManga.manga.source == MERGED_SOURCE_ID) { if (libraryManga.manga.source == MERGED_SOURCE_ID) {
runBlocking { runBlocking {