mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 13:08:56 +01:00
Add "Started" library filter and library update restriction (#6382)
* Add chapter read count to library manga Co-Authored-By: Jays2Kings <jays@outlook.com> * Add "Started" library filter and library update restriction * Update Filter when its changed * Add back accidentally removed stuff. * Update.. * Change variable names * Change Variable name where I missed Co-authored-by: Jays2Kings <jays@outlook.com>
This commit is contained in:
@@ -120,6 +120,7 @@ class LibraryPresenter(
|
||||
val downloadedOnly = preferences.downloadedOnly().get()
|
||||
val filterDownloaded = preferences.filterDownloaded().get()
|
||||
val filterUnread = preferences.filterUnread().get()
|
||||
val filterStarted = preferences.filterStarted().get()
|
||||
val filterCompleted = preferences.filterCompleted().get()
|
||||
val loggedInServices = trackManager.services.filter { trackService -> trackService.isLogged }
|
||||
.associate { trackService ->
|
||||
@@ -127,22 +128,6 @@ class LibraryPresenter(
|
||||
}
|
||||
val isNotAnyLoggedIn = !loggedInServices.values.any()
|
||||
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item ->
|
||||
if (filterUnread == State.IGNORE.value) return@unread true
|
||||
val isUnread = item.manga.unread != 0
|
||||
|
||||
return@unread if (filterUnread == State.INCLUDE.value) isUnread
|
||||
else !isUnread
|
||||
}
|
||||
|
||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item ->
|
||||
if (filterCompleted == State.IGNORE.value) return@completed true
|
||||
val isCompleted = item.manga.status == SManga.COMPLETED
|
||||
|
||||
return@completed if (filterCompleted == State.INCLUDE.value) isCompleted
|
||||
else !isCompleted
|
||||
}
|
||||
|
||||
val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item ->
|
||||
if (!downloadedOnly && filterDownloaded == State.IGNORE.value) return@downloaded true
|
||||
val isDownloaded = when {
|
||||
@@ -155,6 +140,30 @@ class LibraryPresenter(
|
||||
else !isDownloaded
|
||||
}
|
||||
|
||||
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item ->
|
||||
if (filterUnread == State.IGNORE.value) return@unread true
|
||||
val isUnread = item.manga.unreadCount != 0
|
||||
|
||||
return@unread if (filterUnread == State.INCLUDE.value) isUnread
|
||||
else !isUnread
|
||||
}
|
||||
|
||||
val filterFnStarted: (LibraryItem) -> Boolean = started@{ item ->
|
||||
if (filterStarted == State.IGNORE.value) return@started true
|
||||
val hasStarted = item.manga.hasStarted
|
||||
|
||||
return@started if (filterStarted == State.INCLUDE.value) hasStarted
|
||||
else !hasStarted
|
||||
}
|
||||
|
||||
val filterFnCompleted: (LibraryItem) -> Boolean = completed@{ item ->
|
||||
if (filterCompleted == State.IGNORE.value) return@completed true
|
||||
val isCompleted = item.manga.status == SManga.COMPLETED
|
||||
|
||||
return@completed if (filterCompleted == State.INCLUDE.value) isCompleted
|
||||
else !isCompleted
|
||||
}
|
||||
|
||||
val filterFnTracking: (LibraryItem) -> Boolean = tracking@{ item ->
|
||||
if (isNotAnyLoggedIn) return@tracking true
|
||||
|
||||
@@ -181,9 +190,10 @@ class LibraryPresenter(
|
||||
|
||||
val filterFn: (LibraryItem) -> Boolean = filter@{ item ->
|
||||
return@filter !(
|
||||
!filterFnUnread(item) ||
|
||||
!filterFnDownloaded(item) ||
|
||||
!filterFnUnread(item) ||
|
||||
!filterFnStarted(item) ||
|
||||
!filterFnCompleted(item) ||
|
||||
!filterFnDownloaded(item) ||
|
||||
!filterFnTracking(item)
|
||||
)
|
||||
}
|
||||
@@ -212,7 +222,7 @@ class LibraryPresenter(
|
||||
}
|
||||
|
||||
item.unreadCount = if (showUnreadBadges) {
|
||||
item.manga.unread
|
||||
item.manga.unreadCount
|
||||
} else {
|
||||
// Unset unread count if not enabled
|
||||
-1
|
||||
@@ -245,10 +255,6 @@ class LibraryPresenter(
|
||||
var counter = 0
|
||||
db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
val totalChapterManga by lazy {
|
||||
var counter = 0
|
||||
db.getTotalChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
}
|
||||
val latestChapterManga by lazy {
|
||||
var counter = 0
|
||||
db.getLatestChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
|
||||
@@ -262,7 +268,7 @@ class LibraryPresenter(
|
||||
(category.id ?: 0) to SortModeSetting.get(preferences, category)
|
||||
}
|
||||
|
||||
val sortAscending = categories.associate { category ->
|
||||
val sortDirections = categories.associate { category ->
|
||||
(category.id ?: 0) to SortDirectionSetting.get(preferences, category)
|
||||
}
|
||||
|
||||
@@ -272,7 +278,7 @@ class LibraryPresenter(
|
||||
}
|
||||
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
|
||||
val sortingMode = sortingModes[i1.manga.category]!!
|
||||
val sortAscending = sortAscending[i1.manga.category]!! == SortDirectionSetting.ASCENDING
|
||||
val sortAscending = sortDirections[i1.manga.category]!! == SortDirectionSetting.ASCENDING
|
||||
when (sortingMode) {
|
||||
SortModeSetting.ALPHABETICAL -> {
|
||||
collator.compare(i1.manga.title.lowercase(locale), i2.manga.title.lowercase(locale))
|
||||
@@ -286,15 +292,13 @@ class LibraryPresenter(
|
||||
SortModeSetting.LAST_CHECKED -> i2.manga.last_update.compareTo(i1.manga.last_update)
|
||||
SortModeSetting.UNREAD -> when {
|
||||
// Ensure unread content comes first
|
||||
i1.manga.unread == i2.manga.unread -> 0
|
||||
i1.manga.unread == 0 -> if (sortAscending) 1 else -1
|
||||
i2.manga.unread == 0 -> if (sortAscending) -1 else 1
|
||||
else -> i1.manga.unread.compareTo(i2.manga.unread)
|
||||
i1.manga.unreadCount == i2.manga.unreadCount -> 0
|
||||
i1.manga.unreadCount == 0 -> if (sortAscending) 1 else -1
|
||||
i2.manga.unreadCount == 0 -> if (sortAscending) -1 else 1
|
||||
else -> i1.manga.unreadCount.compareTo(i2.manga.unreadCount)
|
||||
}
|
||||
SortModeSetting.TOTAL_CHAPTERS -> {
|
||||
val manga1TotalChapter = totalChapterManga[i1.manga.id!!] ?: 0
|
||||
val mange2TotalChapter = totalChapterManga[i2.manga.id!!] ?: 0
|
||||
manga1TotalChapter.compareTo(mange2TotalChapter)
|
||||
i1.manga.totalChapters.compareTo(i2.manga.totalChapters)
|
||||
}
|
||||
SortModeSetting.LATEST_CHAPTER -> {
|
||||
val manga1latestChapter = latestChapterManga[i1.manga.id!!]
|
||||
@@ -315,7 +319,7 @@ class LibraryPresenter(
|
||||
}
|
||||
|
||||
return map.mapValues { entry ->
|
||||
val sortAscending = sortAscending[entry.key]!! == SortDirectionSetting.ASCENDING
|
||||
val sortAscending = sortDirections[entry.key]!! == SortDirectionSetting.ASCENDING
|
||||
|
||||
val comparator = if (sortAscending) {
|
||||
Comparator(sortFn)
|
||||
|
||||
@@ -89,6 +89,7 @@ class LibrarySettingsSheet(
|
||||
|
||||
private val downloaded = Item.TriStateGroup(R.string.action_filter_downloaded, this)
|
||||
private val unread = Item.TriStateGroup(R.string.action_filter_unread, this)
|
||||
private val started = Item.TriStateGroup(R.string.action_filter_started, this)
|
||||
private val completed = Item.TriStateGroup(R.string.completed, this)
|
||||
private val trackFilters: Map<Int, Item.TriStateGroup>
|
||||
|
||||
@@ -103,7 +104,7 @@ class LibrarySettingsSheet(
|
||||
trackFilters = services.associate { service ->
|
||||
Pair(service.id, Item.TriStateGroup(getServiceResId(service, size), this))
|
||||
}
|
||||
val list: MutableList<Item> = mutableListOf(downloaded, unread, completed)
|
||||
val list: MutableList<Item> = mutableListOf(downloaded, unread, started, completed)
|
||||
if (size > 1) list.add(Item.Header(R.string.action_filter_tracked))
|
||||
list.addAll(trackFilters.values)
|
||||
items = list
|
||||
@@ -122,6 +123,7 @@ class LibrarySettingsSheet(
|
||||
downloaded.state = preferences.filterDownloaded().get()
|
||||
}
|
||||
unread.state = preferences.filterUnread().get()
|
||||
started.state = preferences.filterStarted().get()
|
||||
completed.state = preferences.filterCompleted().get()
|
||||
|
||||
trackFilters.forEach { trackFilter ->
|
||||
@@ -141,6 +143,7 @@ class LibrarySettingsSheet(
|
||||
when (item) {
|
||||
downloaded -> preferences.filterDownloaded().set(newState)
|
||||
unread -> preferences.filterUnread().set(newState)
|
||||
started -> preferences.filterStarted().set(newState)
|
||||
completed -> preferences.filterCompleted().set(newState)
|
||||
else -> {
|
||||
trackFilters.forEach { trackFilter ->
|
||||
|
||||
@@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.data.preference.DEVICE_CHARGING
|
||||
import eu.kanade.tachiyomi.data.preference.DEVICE_ONLY_ON_WIFI
|
||||
import eu.kanade.tachiyomi.data.preference.MANGA_FULLY_READ
|
||||
import eu.kanade.tachiyomi.data.preference.MANGA_ONGOING
|
||||
import eu.kanade.tachiyomi.data.preference.MANGA_STARTED
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.databinding.PrefLibraryColumnsBinding
|
||||
@@ -195,16 +196,16 @@ class SettingsLibraryController : SettingsController() {
|
||||
multiSelectListPreference {
|
||||
bindTo(preferences.libraryUpdateMangaRestriction())
|
||||
titleRes = R.string.pref_library_update_manga_restriction
|
||||
entriesRes = arrayOf(R.string.pref_update_only_completely_read, R.string.pref_update_only_non_completed)
|
||||
entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING)
|
||||
entriesRes = arrayOf(R.string.pref_update_only_completely_read, R.string.pref_update_only_non_completed, R.string.pref_update_only_started)
|
||||
entryValues = arrayOf(MANGA_FULLY_READ, MANGA_ONGOING, MANGA_STARTED)
|
||||
|
||||
fun updateSummary() {
|
||||
val restrictions = preferences.libraryUpdateMangaRestriction().get()
|
||||
.sorted()
|
||||
val restrictions = preferences.libraryUpdateMangaRestriction().get().sorted()
|
||||
.map {
|
||||
when (it) {
|
||||
MANGA_ONGOING -> context.getString(R.string.pref_update_only_non_completed)
|
||||
MANGA_FULLY_READ -> context.getString(R.string.pref_update_only_completely_read)
|
||||
MANGA_STARTED -> context.getString(R.string.pref_update_only_started)
|
||||
else -> it
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user