Fix collapsed categories ignoring filters

This commit is contained in:
Jays2Kings 2022-07-09 15:00:04 -04:00
parent 6ae512a9b5
commit 4b7755d63a

View file

@ -90,6 +90,7 @@ class LibraryPresenter(
private set
var allLibraryItems: List<LibraryItem> = emptyList()
private set
private var hiddenLibraryItems: List<LibraryItem> = emptyList()
var forceShowAllCategories = false
val showAllCategories
get() = forceShowAllCategories || preferences.showAllCategories().get()
@ -157,13 +158,15 @@ class LibraryPresenter(
categories = lastCategories ?: db.getCategories().executeAsBlocking().toMutableList()
}
presenterScope.launch {
val library = withContext(Dispatchers.IO) { getLibraryFromDB() }
library.apply {
setDownloadCount(library)
setUnreadBadge(library)
setSourceLanguage(library)
}
val (library, hiddenItems) = withContext(Dispatchers.IO) { getLibraryFromDB() }
setDownloadCount(library)
setUnreadBadge(library)
setSourceLanguage(library)
setDownloadCount(hiddenItems)
setUnreadBadge(hiddenItems)
setSourceLanguage(hiddenItems)
allLibraryItems = library
hiddenLibraryItems = hiddenItems
var mangaMap = library
mangaMap = applyFilters(mangaMap)
mangaMap = applySort(mangaMap)
@ -262,7 +265,8 @@ class LibraryPresenter(
val missingCategorySet = categories.mapNotNull { it.id }.toMutableSet()
val filteredItems = items.filter f@{ item ->
if (!showEmptyCategoriesWhileFiltering && item.manga.isHidden()) {
val subItems = sectionedLibraryItems[item.manga.category]
val subItems = sectionedLibraryItems[item.manga.category]?.takeUnless { it.size <= 1 }
?: hiddenLibraryItems.filter { it.manga.category == item.manga.category }
if (subItems.isNullOrEmpty()) return@f filtersOff
else {
return@f subItems.any {
@ -544,7 +548,7 @@ class LibraryPresenter(
*
* @return an list of all the manga in a itemized form.
*/
private fun getLibraryFromDB(): List<LibraryItem> {
private fun getLibraryFromDB(): Pair<List<LibraryItem>, List<LibraryItem>> {
removeArticles = preferences.removeArticles().get()
val categories = db.getCategories().executeAsBlocking().toMutableList()
var libraryManga = db.getLibraryMangas().executeAsBlocking()
@ -552,6 +556,7 @@ class LibraryPresenter(
if (groupType > BY_DEFAULT) {
libraryManga = libraryManga.distinctBy { it.id }
}
val hiddenItems = mutableListOf<LibraryItem>()
val items = if (groupType <= BY_DEFAULT || !libraryIsGrouped) {
val categoryAll = Category.createAll(
@ -601,6 +606,7 @@ class LibraryPresenter(
it.manga.title + "-" + it.manga.author
}
sectionedLibraryItems[catId] = mangaToRemove
hiddenItems.addAll(mangaToRemove)
items.removeAll(mangaToRemove)
val headerItem = headerItems[catId]
if (headerItem != null) items.add(
@ -628,7 +634,7 @@ class LibraryPresenter(
this.allCategories = categories
return items
return items to hiddenItems
}
private fun getCustomMangaItems(libraryManga: List<LibraryManga>): Pair<List<LibraryItem>,