Add Filter by Completed for library (#941)
* issue 938 added filter by completed manga status * changed to use existing string fixed space issue in method in presenter
This commit is contained in:
parent
e8b432485d
commit
bfa386acba
4 changed files with 16 additions and 1 deletions
|
@ -87,6 +87,8 @@ object PreferenceKeys {
|
|||
|
||||
const val filterUnread = "pref_filter_unread_key"
|
||||
|
||||
const val filterCompleted = "pref_filter_completed_key"
|
||||
|
||||
const val librarySortingMode = "library_sorting_mode"
|
||||
|
||||
const val automaticUpdates = "automatic_updates"
|
||||
|
|
|
@ -145,6 +145,8 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false)
|
||||
|
||||
fun filterCompleted() = rxPrefs.getBoolean(Keys.filterCompleted, false)
|
||||
|
||||
fun librarySortingMode() = rxPrefs.getInteger(Keys.librarySortingMode, 0)
|
||||
|
||||
fun librarySortingAscending() = rxPrefs.getBoolean("library_sorting_ascending", true)
|
||||
|
|
|
@ -74,7 +74,9 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
|||
|
||||
private val unread = Item.CheckboxGroup(R.string.action_filter_unread, this)
|
||||
|
||||
override val items = listOf(downloaded, unread)
|
||||
private val completed = Item.CheckboxGroup(R.string.completed, this)
|
||||
|
||||
override val items = listOf(downloaded, unread, completed)
|
||||
|
||||
override val header = Item.Header(R.string.action_filter)
|
||||
|
||||
|
@ -83,6 +85,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
|||
override fun initModels() {
|
||||
downloaded.checked = preferences.filterDownloaded().getOrDefault()
|
||||
unread.checked = preferences.filterUnread().getOrDefault()
|
||||
completed.checked = preferences.filterCompleted().getOrDefault()
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: Item) {
|
||||
|
@ -91,6 +94,7 @@ class LibraryNavigationView @JvmOverloads constructor(context: Context, attrs: A
|
|||
when (item) {
|
||||
downloaded -> preferences.filterDownloaded().set(item.checked)
|
||||
unread -> preferences.filterUnread().set(item.checked)
|
||||
completed -> preferences.filterCompleted().set(item.checked)
|
||||
}
|
||||
|
||||
adapter.notifyItemChanged(item)
|
||||
|
|
|
@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.util.combineLatest
|
||||
|
@ -101,6 +102,8 @@ class LibraryPresenter(
|
|||
|
||||
val filterUnread = preferences.filterUnread().getOrDefault()
|
||||
|
||||
val filterCompleted = preferences.filterCompleted().getOrDefault()
|
||||
|
||||
val filterFn: (Manga) -> Boolean = f@ { manga ->
|
||||
// Filter out manga without source.
|
||||
val source = sourceManager.get(manga.source) ?: return@f false
|
||||
|
@ -110,6 +113,10 @@ class LibraryPresenter(
|
|||
return@f false
|
||||
}
|
||||
|
||||
if (filterCompleted && manga.status != SManga.COMPLETED) {
|
||||
return@f false
|
||||
}
|
||||
|
||||
// Filter when the download directory doesn't exist or is null.
|
||||
if (filterDownloaded) {
|
||||
// Get the directories for the source of the manga.
|
||||
|
|
Reference in a new issue