From 5e45c29f5853207f9b5d390d5e60364f893b7a9b Mon Sep 17 00:00:00 2001 From: Jay Date: Sat, 28 Mar 2020 14:10:35 -0400 Subject: [PATCH] Filter library by non tracked services --- .../tachiyomi/ui/library/LibraryPresenter.kt | 34 +++++++++++++------ .../ui/library/filter/FilterBottomSheet.kt | 6 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 4c5a019df4..9a3470ad5a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -169,7 +169,7 @@ class LibraryPresenter( filterTracked == 0 && filterMangaType == 0 } - // Filter when there isn't unread chapters. + // Filter for unread chapters if (filterUnread == STATE_INCLUDE && (item.manga.unread == 0 || db.getChapters(item.manga).executeAsBlocking() .size != item.manga.unread)) return@f false @@ -186,28 +186,42 @@ class LibraryPresenter( else filterMangaType != item.manga.mangaType()) return@f false } + // Filter for completed status of manga if (filterCompleted == STATE_INCLUDE && item.manga.status != SManga.COMPLETED) return@f false if (filterCompleted == STATE_EXCLUDE && item.manga.status == SManga.COMPLETED) return@f false + // Filter for tracked (or per tracked service) if (filterTracked != STATE_IGNORE) { val tracks = db.getTracks(item.manga).executeAsBlocking() - val trackCount = loggedServices.any { service -> + val hasTrack = loggedServices.any { service -> tracks.any { it.sync_id == service.id } } - if (filterTracked == STATE_INCLUDE && !trackCount) return@f false - if (filterTracked == STATE_EXCLUDE && trackCount) return@f false - - if (filterTrackers.isNotEmpty()) { - val service = loggedServices.find { it.name == filterTrackers } - if (service != null) { - if (tracks.none { it.sync_id == service.id }) return@f false + val service = if (filterTrackers.isNotEmpty()) loggedServices.find { + it.name == filterTrackers + } else null + if (filterTracked == STATE_INCLUDE) { + if (!hasTrack) return@f false + if (filterTrackers.isNotEmpty()) { + if (service != null) { + val hasServiceTrack = tracks.any { it.sync_id == service.id } + if (!hasServiceTrack) return@f false + if (filterTracked == STATE_EXCLUDE && hasServiceTrack) return@f false + } + } + } else if (filterTracked == STATE_EXCLUDE) { + if (!hasTrack && filterTrackers.isEmpty()) return@f false + if (filterTrackers.isNotEmpty()) { + if (service != null) { + val hasServiceTrack = tracks.any { it.sync_id == service.id } + if (hasServiceTrack) return@f false + } } } } - // Filter when there are no downloads. + // Filter for downloaded manga if (filterDownloaded != STATE_IGNORE) { val isDownloaded = when { item.manga.source == LocalSource.ID -> true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 6b52296f66..14813778a6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -271,12 +271,10 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } onGroupClicked(ACTION_FILTER) } - if (preferences.filterTracked().getOrDefault() == 1 && - trackers != null && trackers?.parent == null) { + if (tracked.isActivated && trackers != null && trackers?.parent == null) { filter_layout.addView(trackers) filterItems.add(trackers!!) - } else if (preferences.filterTracked().getOrDefault() != 1 && - trackers?.parent != null) { + } else if (!tracked.isActivated && trackers?.parent != null) { filter_layout.removeView(trackers) trackers?.reset() FILTER_TRACKER = ""