Implement library filter for tracked items (#1)
* Implement library filter for tracked items * Revert formatting * Move string 'tracked' Co-authored-by: she11sh0cked <she11sh0cked@users.noreply.github.com>
This commit is contained in:
parent
fa29b914cc
commit
6a0ab3526a
@ -109,6 +109,8 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val filterCompleted = "pref_filter_completed_key"
|
const val filterCompleted = "pref_filter_completed_key"
|
||||||
|
|
||||||
|
const val filterTracked = "pref_filter_tracked_key"
|
||||||
|
|
||||||
const val librarySortingMode = "library_sorting_mode"
|
const val librarySortingMode = "library_sorting_mode"
|
||||||
|
|
||||||
const val automaticExtUpdates = "automatic_ext_updates"
|
const val automaticExtUpdates = "automatic_ext_updates"
|
||||||
|
@ -202,6 +202,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun filterCompleted() = flowPrefs.getInt(Keys.filterCompleted, 0)
|
fun filterCompleted() = flowPrefs.getInt(Keys.filterCompleted, 0)
|
||||||
|
|
||||||
|
fun filterTracked() = flowPrefs.getInt(Keys.filterTracked, 0)
|
||||||
|
|
||||||
fun librarySortingMode() = flowPrefs.getInt(Keys.librarySortingMode, 0)
|
fun librarySortingMode() = flowPrefs.getInt(Keys.librarySortingMode, 0)
|
||||||
|
|
||||||
fun librarySortingAscending() = flowPrefs.getBoolean("library_sorting_ascending", true)
|
fun librarySortingAscending() = flowPrefs.getBoolean("library_sorting_ascending", true)
|
||||||
|
@ -130,6 +130,7 @@ class LibraryPresenter(
|
|||||||
val filterDownloadedOnly = preferences.downloadedOnly().get()
|
val filterDownloadedOnly = preferences.downloadedOnly().get()
|
||||||
val filterUnread = preferences.filterUnread().get()
|
val filterUnread = preferences.filterUnread().get()
|
||||||
val filterCompleted = preferences.filterCompleted().get()
|
val filterCompleted = preferences.filterCompleted().get()
|
||||||
|
val filterTracked = preferences.filterTracked().get()
|
||||||
|
|
||||||
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.
|
||||||
@ -145,6 +146,11 @@ 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 tracks = db.getTracks(item.manga).executeAsBlocking()
|
||||||
|
if (filterTracked == STATE_INCLUDE && tracks.isEmpty()) return@f false
|
||||||
|
else if (filterTracked == STATE_EXCLUDE && tracks.isNotEmpty()) return@f false
|
||||||
|
}
|
||||||
// Filter when there are no downloads.
|
// Filter when there are no downloads.
|
||||||
if (filterDownloaded != STATE_IGNORE || filterDownloadedOnly) {
|
if (filterDownloaded != STATE_IGNORE || filterDownloadedOnly) {
|
||||||
val isDownloaded = when {
|
val isDownloaded = when {
|
||||||
|
@ -70,9 +70,10 @@ class LibrarySettingsSheet(
|
|||||||
private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this)
|
private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this)
|
||||||
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
|
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
|
||||||
private val completed = Item.TriStateGroup(R.string.completed, this)
|
private val completed = Item.TriStateGroup(R.string.completed, this)
|
||||||
|
private val tracked = Item.TriStateGroup(R.string.tracked, this)
|
||||||
|
|
||||||
override val header = null
|
override val header = null
|
||||||
override val items = listOf(downloaded, unread, completed)
|
override val items = listOf(downloaded, unread, completed, tracked)
|
||||||
override val footer = null
|
override val footer = null
|
||||||
|
|
||||||
override fun initModels() { // j2k changes
|
override fun initModels() { // j2k changes
|
||||||
@ -80,6 +81,7 @@ class LibrarySettingsSheet(
|
|||||||
downloaded.state = preferences.filterDownloaded().get()
|
downloaded.state = preferences.filterDownloaded().get()
|
||||||
unread.state = preferences.filterUnread().get()
|
unread.state = preferences.filterUnread().get()
|
||||||
completed.state = preferences.filterCompleted().get()
|
completed.state = preferences.filterCompleted().get()
|
||||||
|
tracked.state = preferences.filterTracked().get()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
preferences.upgradeFilters()
|
preferences.upgradeFilters()
|
||||||
}
|
}
|
||||||
@ -97,6 +99,7 @@ class LibrarySettingsSheet(
|
|||||||
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)
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
<string name="action_copy_now">Copy now</string>
|
<string name="action_copy_now">Copy now</string>
|
||||||
|
|
||||||
<!-- Preferences -->
|
<!-- Preferences -->
|
||||||
|
<!-- Filter -->
|
||||||
|
<string name="tracked">Tracked</string>
|
||||||
|
|
||||||
<!-- Subsections -->
|
<!-- Subsections -->
|
||||||
<string name="pref_category_all_sources">All Sources</string>
|
<string name="pref_category_all_sources">All Sources</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user