Use tristate checkboxes for chapters list filters
This commit is contained in:
@@ -19,8 +19,7 @@ import eu.kanade.tachiyomi.util.lang.combineLatest
|
||||
import eu.kanade.tachiyomi.util.lang.isNullOrUnsubscribed
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.removeCovers
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_IGNORE
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_INCLUDE
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@@ -118,30 +117,30 @@ class LibraryPresenter(
|
||||
val filterCompleted = preferences.filterCompleted().get()
|
||||
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item ->
|
||||
if (filterUnread == STATE_IGNORE) return@unread true
|
||||
if (filterUnread == State.IGNORE.value) return@unread true
|
||||
val isUnread = item.manga.unread != 0
|
||||
|
||||
return@unread if (filterUnread == STATE_INCLUDE) isUnread
|
||||
return@unread if (filterUnread == State.INCLUDE.value) isUnread
|
||||
else !isUnread
|
||||
}
|
||||
|
||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item ->
|
||||
if (filterCompleted == STATE_IGNORE) return@completed true
|
||||
if (filterCompleted == State.IGNORE.value) return@completed true
|
||||
val isCompleted = item.manga.status == SManga.COMPLETED
|
||||
|
||||
return@completed if (filterCompleted == STATE_INCLUDE) isCompleted
|
||||
return@completed if (filterCompleted == State.INCLUDE.value) isCompleted
|
||||
else !isCompleted
|
||||
}
|
||||
|
||||
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item ->
|
||||
if (!downloadedOnly && filterDownloaded == STATE_IGNORE) return@downloaded true
|
||||
if (!downloadedOnly && filterDownloaded == State.IGNORE.value) return@downloaded true
|
||||
val isDownloaded = when {
|
||||
item.manga.isLocal() -> true
|
||||
item.downloadCount != -1 -> item.downloadCount > 0
|
||||
else -> downloadManager.getDownloadCount(item.manga) > 0
|
||||
}
|
||||
|
||||
return@downloaded if (downloadedOnly || filterDownloaded == STATE_INCLUDE) isDownloaded
|
||||
return@downloaded if (downloadedOnly || filterDownloaded == State.INCLUDE.value) isDownloaded
|
||||
else !isDownloaded
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.DisplayMode
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_EXCLUDE
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_IGNORE
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_INCLUDE
|
||||
import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State
|
||||
import eu.kanade.tachiyomi.widget.TabbedBottomSheetDialog
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
@@ -62,7 +60,7 @@ class LibrarySettingsSheet(
|
||||
* Returns true if there's at least one filter from [FilterGroup] active.
|
||||
*/
|
||||
fun hasActiveFilters(): Boolean {
|
||||
return filterGroup.items.any { it.state != STATE_IGNORE }
|
||||
return filterGroup.items.any { it.state != State.IGNORE.value }
|
||||
}
|
||||
|
||||
inner class FilterGroup : Group {
|
||||
@@ -77,7 +75,7 @@ class LibrarySettingsSheet(
|
||||
|
||||
override fun initModels() {
|
||||
if (preferences.downloadedOnly().get()) {
|
||||
downloaded.state = STATE_INCLUDE
|
||||
downloaded.state = State.INCLUDE.value
|
||||
downloaded.enabled = false
|
||||
} else {
|
||||
downloaded.state = preferences.filterDownloaded().get()
|
||||
@@ -89,9 +87,9 @@ class LibrarySettingsSheet(
|
||||
override fun onItemClicked(item: Item) {
|
||||
item as Item.TriStateGroup
|
||||
val newState = when (item.state) {
|
||||
STATE_IGNORE -> STATE_INCLUDE
|
||||
STATE_INCLUDE -> STATE_EXCLUDE
|
||||
STATE_EXCLUDE -> STATE_IGNORE
|
||||
State.IGNORE.value -> State.INCLUDE.value
|
||||
State.INCLUDE.value -> State.EXCLUDE.value
|
||||
State.EXCLUDE.value -> State.IGNORE.value
|
||||
else -> throw Exception("Unknown State")
|
||||
}
|
||||
item.state = newState
|
||||
|
||||
Reference in New Issue
Block a user