mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
enhance(library): Show "category is empty" on filtered if the category is actually empty
This commit is contained in:
parent
25644af5cf
commit
a25df1eef3
3 changed files with 16 additions and 2 deletions
|
@ -14,6 +14,13 @@ data class LibraryManga(
|
||||||
var lastFetch: Int = 0,
|
var lastFetch: Int = 0,
|
||||||
) : MangaImpl() {
|
) : 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
|
val hasRead
|
||||||
get() = read > 0
|
get() = read > 0
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class LibraryListHolder(
|
||||||
binding.title.isVisible = false
|
binding.title.isVisible = false
|
||||||
} else {
|
} else {
|
||||||
binding.title.text = itemView.context.getString(
|
binding.title.text = itemView.context.getString(
|
||||||
if (adapter.hasActiveFilters) {
|
if (adapter.hasActiveFilters && item.manga.realMangaCount >= 1) {
|
||||||
R.string.no_matches_for_filters_short
|
R.string.no_matches_for_filters_short
|
||||||
} else {
|
} else {
|
||||||
R.string.category_is_empty
|
R.string.category_is_empty
|
||||||
|
|
|
@ -341,7 +341,12 @@ class LibraryPresenter(
|
||||||
)
|
)
|
||||||
hasActiveFilters = !filtersOff
|
hasActiveFilters = !filtersOff
|
||||||
val missingCategorySet = categories.mapNotNull { it.id }.toMutableSet()
|
val missingCategorySet = categories.mapNotNull { it.id }.toMutableSet()
|
||||||
|
val realCount = mutableMapOf<Int, Int>()
|
||||||
val filteredItems = this.filter f@{ item ->
|
val filteredItems = this.filter f@{ item ->
|
||||||
|
if (showEmptyCategoriesWhileFiltering) {
|
||||||
|
realCount[item.manga.category] = sectionedLibraryItems[item.manga.category]?.size ?: 0
|
||||||
|
}
|
||||||
|
|
||||||
if (!showEmptyCategoriesWhileFiltering && item.manga.isHidden()) {
|
if (!showEmptyCategoriesWhileFiltering && item.manga.isHidden()) {
|
||||||
val subItems = sectionedLibraryItems[item.manga.category]?.takeUnless { it.size <= 1 }
|
val subItems = sectionedLibraryItems[item.manga.category]?.takeUnless { it.size <= 1 }
|
||||||
?: hiddenLibraryItems.filter { it.manga.category == item.manga.category }
|
?: hiddenLibraryItems.filter { it.manga.category == item.manga.category }
|
||||||
|
@ -376,7 +381,9 @@ class LibraryPresenter(
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
if (showEmptyCategoriesWhileFiltering) {
|
if (showEmptyCategoriesWhileFiltering) {
|
||||||
missingCategorySet.forEach {
|
missingCategorySet.forEach {
|
||||||
filteredItems.add(blankItem(it).first())
|
filteredItems.add(
|
||||||
|
blankItem(it).first().apply { manga.realMangaCount = realCount[it] ?: 0 }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredItems
|
return filteredItems
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue