Filter Library by Tracked

This commit is contained in:
Jay 2020-01-13 04:16:55 -08:00
parent 09bb216cda
commit 2595405722
5 changed files with 20 additions and 1 deletions

View file

@ -97,6 +97,8 @@ object PreferenceKeys {
const val filterCompleted = "pref_filter_completed_key" const val filterCompleted = "pref_filter_completed_key"
const val filterTrcaked = "pref_filter_tracked_key"
const val librarySortingMode = "library_sorting_mode" const val librarySortingMode = "library_sorting_mode"
const val automaticUpdates = "automatic_updates" const val automaticUpdates = "automatic_updates"

View file

@ -159,6 +159,8 @@ class PreferencesHelper(val context: Context) {
fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0) fun filterCompleted() = rxPrefs.getInteger(Keys.filterCompleted, 0)
fun filterTracked() = rxPrefs.getInteger(Keys.filterTrcaked, 0)
fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0) fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0)
fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true) fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true)

View file

@ -176,6 +176,7 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
fun canDrag(): Boolean { fun canDrag(): Boolean {
val sortingMode = preferences.librarySortingMode().getOrDefault() val sortingMode = preferences.librarySortingMode().getOrDefault()
val filterOff = preferences.filterCompleted().getOrDefault() + val filterOff = preferences.filterCompleted().getOrDefault() +
preferences.filterTracked().getOrDefault() +
preferences.filterUnread().getOrDefault() + preferences.filterUnread().getOrDefault() +
preferences.filterCompleted().getOrDefault() == 0 preferences.filterCompleted().getOrDefault() == 0
return sortingMode == LibrarySort.DRAG_AND_DROP && filterOff && return sortingMode == LibrarySort.DRAG_AND_DROP && filterOff &&

View file

@ -79,7 +79,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
private val completed = Item.TriStateGroup(R.string.completed, this) 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) 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() downloaded.state = preferences.filterDownloaded().getOrDefault()
unread.state = preferences.filterUnread().getOrDefault() unread.state = preferences.filterUnread().getOrDefault()
completed.state = preferences.filterCompleted().getOrDefault() completed.state = preferences.filterCompleted().getOrDefault()
tracked.state = preferences.filterTracked().getOrDefault()
tracked
} }
catch (e: Exception) { catch (e: Exception) {
preferences.upgradeFilters() preferences.upgradeFilters()
@ -108,6 +112,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
downloaded -> preferences.filterDownloaded().set(item.state) downloaded -> preferences.filterDownloaded().set(item.state)
unread -> preferences.filterUnread().set(item.state) unread -> preferences.filterUnread().set(item.state)
completed -> preferences.filterCompleted().set(item.state) completed -> preferences.filterCompleted().set(item.state)
tracked -> preferences.filterTracked().set(item.state)
} }
adapter.notifyItemChanged(item) adapter.notifyItemChanged(item)

View file

@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault 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.LocalSource
import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
@ -127,6 +128,8 @@ class LibraryPresenter(
val filterCompleted = preferences.filterCompleted().getOrDefault() val filterCompleted = preferences.filterCompleted().getOrDefault()
val filterTracked = preferences.filterTracked().getOrDefault()
val filterFn: (LibraryItem) -> Boolean = f@ { item -> val filterFn: (LibraryItem) -> Boolean = f@ { item ->
// Filter when there isn't unread chapters. // Filter when there isn't unread chapters.
if (filterUnread == STATE_INCLUDE && item.manga.unread == 0) return@f false 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) if (filterCompleted == STATE_EXCLUDE && item.manga.status == SManga.COMPLETED)
return@f false return@f false
if (filterTracked != STATE_IGNORE) {
val db = Injekt.get<DatabaseHelper>()
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. // Filter when there are no downloads.
if (filterDownloaded != STATE_IGNORE) { if (filterDownloaded != STATE_IGNORE) {
val isDownloaded = when { val isDownloaded = when {