Filters now work on collasped categories

closes #317
This commit is contained in:
Jay 2020-05-04 16:17:40 -04:00
parent ba2d5e4a6d
commit 0a1c036cc9
4 changed files with 91 additions and 69 deletions

View File

@ -34,6 +34,9 @@ class LibraryCategoryAdapter(val controller: LibraryController) :
val libraryListener: LibraryListener = controller val libraryListener: LibraryListener = controller
val isSingleCategory
get() = controller.singleCategory || !controller.presenter.showAllCategories
/** /**
* Sets a list of manga in the adapter. * Sets a list of manga in the adapter.
* *

View File

@ -116,7 +116,8 @@ class LibraryController(
private var libraryLayout: Int = preferences.libraryLayout().getOrDefault() private var libraryLayout: Int = preferences.libraryLayout().getOrDefault()
private var singleCategory: Boolean = false var singleCategory: Boolean = false
private set
/** /**
* Library search query. * Library search query.

View File

@ -184,16 +184,16 @@ class LibraryHeaderItem(
updateButton.gone() updateButton.gone()
} }
LibraryUpdateService.categoryInQueue(category.id) -> { LibraryUpdateService.categoryInQueue(category.id) -> {
expandImage.visibleIf(adapter.headerItems.size > 1) expandImage.visibleIf(!adapter.isSingleCategory)
checkboxImage.gone() checkboxImage.gone()
catProgress.visible() catProgress.visible()
updateButton.invisible() updateButton.invisible()
} }
else -> { else -> {
expandImage.visibleIf(adapter.headerItems.size > 1) expandImage.visibleIf(!adapter.isSingleCategory)
catProgress.gone() catProgress.gone()
checkboxImage.gone() checkboxImage.gone()
updateButton.visInvisIf(category.id ?: 0 > -1 && adapter.headerItems.size > 1) updateButton.visInvisIf(category.id ?: 0 > -1 && !adapter.isSingleCategory)
} }
} }
} }

View File

@ -60,7 +60,7 @@ class LibraryPresenter(
/** List of all manga to update the */ /** List of all manga to update the */
var libraryItems: List<LibraryItem> = emptyList() var libraryItems: List<LibraryItem> = emptyList()
private var sectionedLibraryItems: Map<Int, List<LibraryItem>> = emptyMap() private var sectionedLibraryItems: MutableMap<Int, List<LibraryItem>> = mutableMapOf()
var currentCategory = -1 var currentCategory = -1
private set private set
private var allLibraryItems: List<LibraryItem> = emptyList() private var allLibraryItems: List<LibraryItem> = emptyList()
@ -117,7 +117,7 @@ class LibraryPresenter(
val items = libraryItems val items = libraryItems
val show = showAllCategories || preferences.hideCategories().getOrDefault() val show = showAllCategories || preferences.hideCategories().getOrDefault()
if (!show) { if (!show) {
sectionedLibraryItems = items.groupBy { it.manga.category } sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap()
if (currentCategory == -1) currentCategory = categories.find { if (currentCategory == -1) currentCategory = categories.find {
it.order == preferences.lastUsedCategory().getOrDefault() it.order == preferences.lastUsedCategory().getOrDefault()
}?.id ?: 0 }?.id ?: 0
@ -133,7 +133,7 @@ class LibraryPresenter(
libraryItems = items libraryItems = items
val show = showAllCategories || preferences.hideCategories().getOrDefault() val show = showAllCategories || preferences.hideCategories().getOrDefault()
if (!show) { if (!show) {
sectionedLibraryItems = items.groupBy { it.manga.category } sectionedLibraryItems = items.groupBy { it.manga.category }.toMutableMap()
if (currentCategory == -1) currentCategory = categories.find { if (currentCategory == -1) currentCategory = categories.find {
it.order == preferences.lastUsedCategory().getOrDefault() it.order == preferences.lastUsedCategory().getOrDefault()
}?.id ?: 0 }?.id ?: 0
@ -166,31 +166,49 @@ class LibraryPresenter(
val filterTrackers = FilterBottomSheet.FILTER_TRACKER val filterTrackers = FilterBottomSheet.FILTER_TRACKER
return items.filter f@{ item -> return items.filter f@{ item ->
if (item.manga.isBlank()) { if (item.manga.status == -1) {
return@f sectionedLibraryItems[item.manga.category]?.any {
matchesFilters(it, filterDownloaded, filterUnread, filterCompleted,
filterTracked, filterMangaType, filterTrackers)
} ?: false
} else if (item.manga.isBlank()) {
return@f filterDownloaded == 0 && filterUnread == 0 && filterCompleted == 0 && return@f filterDownloaded == 0 && filterUnread == 0 && filterCompleted == 0 &&
filterTracked == 0 && filterMangaType == 0 filterTracked == 0 && filterMangaType == 0
} }
matchesFilters(item, filterDownloaded, filterUnread, filterCompleted, filterTracked,
filterMangaType, filterTrackers)
}
}
if (filterUnread == STATE_INCLUDE && item.manga.unread == 0) return@f false private fun matchesFilters(
if (filterUnread == STATE_EXCLUDE && item.manga.unread > 0) return@f false item: LibraryItem,
filterDownloaded: Int,
filterUnread: Int,
filterCompleted: Int,
filterTracked: Int,
filterMangaType: Int,
filterTrackers: String
): Boolean {
if (filterUnread == STATE_INCLUDE && item.manga.unread == 0) return false
if (filterUnread == STATE_EXCLUDE && item.manga.unread > 0) return false
// Filter for unread chapters // Filter for unread chapters
if (filterUnread == 3 && (item.manga.unread == 0 || db.getChapters(item.manga) if (filterUnread == 3 && (item.manga.unread == 0 || db.getChapters(item.manga)
.executeAsBlocking().size != item.manga.unread) .executeAsBlocking().size != item.manga.unread)
) return@f false ) return false
if (filterUnread == 4 && (item.manga.unread == 0 || db.getChapters(item.manga) if (filterUnread == 4 && (item.manga.unread == 0 || db.getChapters(item.manga)
.executeAsBlocking().size == item.manga.unread) .executeAsBlocking().size == item.manga.unread)
) return@f false ) return false
if (filterMangaType > 0) { if (filterMangaType > 0) {
if (if (filterMangaType == Manga.TYPE_MANHWA) (filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON) if (if (filterMangaType == Manga.TYPE_MANHWA) (filterMangaType != item.manga.mangaType() && filterMangaType != Manga.TYPE_WEBTOON)
else filterMangaType != item.manga.mangaType() else filterMangaType != item.manga.mangaType()
) return@f false ) return false
} }
// Filter for completed status of manga // Filter for completed status of manga
if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED) return@f false if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED) return false
if (filterCompleted == STATE_EXCLUDE && item.manga.status == SManga.COMPLETED) return@f false if (filterCompleted == STATE_EXCLUDE && item.manga.status == SManga.COMPLETED) return false
// Filter for tracked (or per tracked service) // Filter for tracked (or per tracked service)
if (filterTracked != STATE_IGNORE) { if (filterTracked != STATE_IGNORE) {
@ -203,20 +221,20 @@ class LibraryPresenter(
it.name == filterTrackers it.name == filterTrackers
} else null } else null
if (filterTracked == STATE_INCLUDE) { if (filterTracked == STATE_INCLUDE) {
if (!hasTrack) return@f false if (!hasTrack) return false
if (filterTrackers.isNotEmpty()) { if (filterTrackers.isNotEmpty()) {
if (service != null) { if (service != null) {
val hasServiceTrack = tracks.any { it.sync_id == service.id } val hasServiceTrack = tracks.any { it.sync_id == service.id }
if (!hasServiceTrack) return@f false if (!hasServiceTrack) return false
if (filterTracked == STATE_EXCLUDE && hasServiceTrack) return@f false if (filterTracked == STATE_EXCLUDE && hasServiceTrack) return false
} }
} }
} else if (filterTracked == STATE_EXCLUDE) { } else if (filterTracked == STATE_EXCLUDE) {
if (hasTrack && filterTrackers.isEmpty()) return@f false if (hasTrack && filterTrackers.isEmpty()) return false
if (filterTrackers.isNotEmpty()) { if (filterTrackers.isNotEmpty()) {
if (service != null) { if (service != null) {
val hasServiceTrack = tracks.any { it.sync_id == service.id } val hasServiceTrack = tracks.any { it.sync_id == service.id }
if (hasServiceTrack) return@f false if (hasServiceTrack) return false
} }
} }
} }
@ -228,10 +246,9 @@ class LibraryPresenter(
item.downloadCount != -1 -> item.downloadCount > 0 item.downloadCount != -1 -> item.downloadCount > 0
else -> downloadManager.getDownloadCount(item.manga) > 0 else -> downloadManager.getDownloadCount(item.manga) > 0
} }
return@f if (filterDownloaded == STATE_INCLUDE) isDownloaded else !isDownloaded return if (filterDownloaded == STATE_INCLUDE) isDownloaded else !isDownloaded
}
true
} }
return true
} }
/** /**
@ -487,6 +504,7 @@ class LibraryPresenter(
val mergedTitle = mangaToRemove.joinToString("-") { val mergedTitle = mangaToRemove.joinToString("-") {
it.manga.title + "-" + it.manga.author it.manga.title + "-" + it.manga.author
} }
sectionedLibraryItems[catId] = mangaToRemove
items.removeAll(mangaToRemove) items.removeAll(mangaToRemove)
val headerItem = headerItems[catId] val headerItem = headerItems[catId]
if (headerItem != null) items.add( if (headerItem != null) items.add(