enhance(library): Show "category is empty" on filtered if the category is actually empty

This commit is contained in:
Ahmad Ansori Palembani 2024-06-21 21:26:03 +07:00
parent 25644af5cf
commit a25df1eef3
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
3 changed files with 16 additions and 2 deletions

View file

@ -14,6 +14,13 @@ data class LibraryManga(
var lastFetch: Int = 0,
) : MangaImpl() {
var realMangaCount = 0
get() = if (isBlank()) field else throw IllegalStateException("realMangaCount is only accessible for placeholders")
set(value) {
if (!isBlank()) throw IllegalStateException("realMangaCount can only be set for placeholders")
field = value
}
val hasRead
get() = read > 0

View file

@ -48,7 +48,7 @@ class LibraryListHolder(
binding.title.isVisible = false
} else {
binding.title.text = itemView.context.getString(
if (adapter.hasActiveFilters) {
if (adapter.hasActiveFilters && item.manga.realMangaCount >= 1) {
R.string.no_matches_for_filters_short
} else {
R.string.category_is_empty

View file

@ -341,7 +341,12 @@ class LibraryPresenter(
)
hasActiveFilters = !filtersOff
val missingCategorySet = categories.mapNotNull { it.id }.toMutableSet()
val realCount = mutableMapOf<Int, Int>()
val filteredItems = this.filter f@{ item ->
if (showEmptyCategoriesWhileFiltering) {
realCount[item.manga.category] = sectionedLibraryItems[item.manga.category]?.size ?: 0
}
if (!showEmptyCategoriesWhileFiltering && item.manga.isHidden()) {
val subItems = sectionedLibraryItems[item.manga.category]?.takeUnless { it.size <= 1 }
?: hiddenLibraryItems.filter { it.manga.category == item.manga.category }
@ -376,7 +381,9 @@ class LibraryPresenter(
}.toMutableList()
if (showEmptyCategoriesWhileFiltering) {
missingCategorySet.forEach {
filteredItems.add(blankItem(it).first())
filteredItems.add(
blankItem(it).first().apply { manga.realMangaCount = realCount[it] ?: 0 }
)
}
}
return filteredItems