mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-23 21:27:40 +03:00
Fix downloaded badges appearing when filtering by downloaded
Fixes #8850
This commit is contained in:
parent
920ca405a2
commit
c4c6e41c46
1 changed files with 22 additions and 30 deletions
|
@ -96,7 +96,8 @@ class LibraryScreenModel(
|
|||
getLibraryFlow(),
|
||||
getTracksPerManga.subscribe(),
|
||||
getTrackingFilterFlow(),
|
||||
) { searchQuery, library, tracks, loggedInTrackServices ->
|
||||
downloadCache.changes,
|
||||
) { searchQuery, library, tracks, loggedInTrackServices, _ ->
|
||||
library
|
||||
.applyFilters(tracks, loggedInTrackServices)
|
||||
.applySort()
|
||||
|
@ -180,14 +181,12 @@ class LibraryScreenModel(
|
|||
val includedTracks = loggedInTrackServices.mapNotNull { if (it.value == TriStateGroup.State.INCLUDE.value) it.key else null }
|
||||
val trackFiltersIsIgnored = includedTracks.isEmpty() && excludedTracks.isEmpty()
|
||||
|
||||
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item ->
|
||||
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{
|
||||
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) {
|
||||
isDownloaded
|
||||
} else {
|
||||
|
@ -195,10 +194,10 @@ class LibraryScreenModel(
|
|||
}
|
||||
}
|
||||
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item ->
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{
|
||||
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) {
|
||||
isUnread
|
||||
} else {
|
||||
|
@ -206,10 +205,10 @@ class LibraryScreenModel(
|
|||
}
|
||||
}
|
||||
|
||||
val filterFnStarted: (LibraryItem) -> Boolean = started@{ item ->
|
||||
val filterFnStarted: (LibraryItem) -> Boolean = started@{
|
||||
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) {
|
||||
hasStarted
|
||||
} else {
|
||||
|
@ -217,11 +216,10 @@ class LibraryScreenModel(
|
|||
}
|
||||
}
|
||||
|
||||
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{ item ->
|
||||
val filterFnBookmarked: (LibraryItem) -> Boolean = bookmarked@{
|
||||
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) {
|
||||
hasBookmarks
|
||||
} else {
|
||||
|
@ -229,10 +227,10 @@ class LibraryScreenModel(
|
|||
}
|
||||
}
|
||||
|
||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item ->
|
||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{
|
||||
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) {
|
||||
isCompleted
|
||||
} else {
|
||||
|
@ -260,14 +258,14 @@ class LibraryScreenModel(
|
|||
return@tracking false
|
||||
}
|
||||
|
||||
val filterFn: (LibraryItem) -> Boolean = filter@{ item ->
|
||||
val filterFn: (LibraryItem) -> Boolean = filter@{
|
||||
return@filter !(
|
||||
!filterFnDownloaded(item) ||
|
||||
!filterFnUnread(item) ||
|
||||
!filterFnStarted(item) ||
|
||||
!filterFnBookmarked(item) ||
|
||||
!filterFnCompleted(item) ||
|
||||
!filterFnTracking(item)
|
||||
!filterFnDownloaded(it) ||
|
||||
!filterFnUnread(it) ||
|
||||
!filterFnStarted(it) ||
|
||||
!filterFnBookmarked(it) ||
|
||||
!filterFnCompleted(it) ||
|
||||
!filterFnTracking(it)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -363,8 +361,6 @@ class LibraryScreenModel(
|
|||
|
||||
/**
|
||||
* Get the categories and all its manga from the database.
|
||||
*
|
||||
* @return an observable of the categories and its manga.
|
||||
*/
|
||||
private fun getLibraryFlow(): Flow<LibraryMap> {
|
||||
val libraryMangasFlow = combine(
|
||||
|
@ -374,13 +370,9 @@ class LibraryScreenModel(
|
|||
) { libraryMangaList, prefs, _ ->
|
||||
libraryMangaList
|
||||
.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
|
||||
LibraryItem(libraryManga).apply {
|
||||
downloadCount = if (needsDownloadCounts) {
|
||||
downloadCount = if (prefs.downloadBadge) {
|
||||
downloadManager.getDownloadCount(libraryManga.manga).toLong()
|
||||
} else {
|
||||
0
|
||||
|
|
Loading…
Reference in a new issue