From 2595405722177d59b5a54b24b61aa75c66d38fa9 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 13 Jan 2020 04:16:55 -0800 Subject: [PATCH] Filter Library by Tracked --- .../kanade/tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../kanade/tachiyomi/ui/library/LibraryCategoryView.kt | 1 + .../kanade/tachiyomi/ui/library/LibraryNavigationView.kt | 7 ++++++- .../eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt | 9 +++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index d84968cd70..676b68bd32 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -97,6 +97,8 @@ object PreferenceKeys { const val filterCompleted = "pref_filter_completed_key" + const val filterTrcaked = "pref_filter_tracked_key" + const val librarySortingMode = "library_sorting_mode" const val automaticUpdates = "automatic_updates" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index a24212f299..f2d952b6a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -159,6 +159,8 @@ class PreferencesHelper(val context: Context) { fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0) + fun filterTracked() = rxPrefs.getInteger(Keys.filterTrcaked, 0) + fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0) fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt index bb5945d385..994ca425ed 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryView.kt @@ -176,6 +176,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att fun canDrag(): Boolean { val sortingMode = preferences.librarySortingMode().getOrDefault() val filterOff = preferences.filterCompleted().getOrDefault() + + preferences.filterTracked().getOrDefault() + preferences.filterUnread().getOrDefault() + preferences.filterCompleted().getOrDefault() == 0 return sortingMode == LibrarySort.DRAG_AND_DROP && filterOff && diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt index 9df4b79f1c..9172fc0d15 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryNavigationView.kt @@ -79,7 +79,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A private val completed = Item.TriStateGroup(R.string.completed, this) - override val items = listOf(downloaded, unread, completed) + private val tracked = Item.TriStateGroup(R.string.tracked, this) + + override val items = listOf(downloaded, unread, completed, tracked) override val header = Item.Header(R.string.action_filter) @@ -90,6 +92,8 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A downloaded.state = preferences.filterDownloaded().getOrDefault() unread.state = preferences.filterUnread().getOrDefault() completed.state = preferences.filterCompleted().getOrDefault() + tracked.state = preferences.filterTracked().getOrDefault() + tracked } catch (e: Exception) { preferences.upgradeFilters() @@ -108,6 +112,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A downloaded -> preferences.filterDownloaded().set(item.state) unread -> preferences.filterUnread().set(item.state) completed -> preferences.filterCompleted().set(item.state) + tracked -> preferences.filterTracked().set(item.state) } adapter.notifyItemChanged(item) 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 9e78ab0f98..cebb978dee 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 @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.SourceManager @@ -127,6 +128,8 @@ class LibraryPresenter( val filterCompleted = preferences.filterCompleted().getOrDefault() + val filterTracked = preferences.filterTracked().getOrDefault() + val filterFn: (LibraryItem) -> Boolean = f@ { item -> // Filter when there isn't unread chapters. if (filterUnread == STATE_INCLUDE && item.manga.unread == 0) return@f false @@ -137,6 +140,12 @@ class LibraryPresenter( if (filterCompleted == STATE_EXCLUDE && item.manga.status == SManga.COMPLETED) return@f false + if (filterTracked != STATE_IGNORE) { + val db = Injekt.get() + val tracks = db.getTracks(item.manga).executeAsBlocking().size + if (filterTracked == STATE_INCLUDE && tracks == 0) return@f false + if (filterTracked == STATE_EXCLUDE && tracks > 0) return@f false + } // Filter when there are no downloads. if (filterDownloaded != STATE_IGNORE) { val isDownloaded = when {