|
@@ -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,14 +128,34 @@ class LibraryPresenter(
|
|
|
}
|
|
|
val isNotAnyLoggedIn = !loggedInServices.values.any()
|
|
|
|
|
|
+ val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item ->
|
|
|
+ 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.value) isDownloaded
|
|
|
+ else !isDownloaded
|
|
|
+ }
|
|
|
+
|
|
|
val filterFnUnread: (LibraryItem) -> Boolean = unread@{ item ->
|
|
|
if (filterUnread == State.IGNORE.value) return@unread true
|
|
|
- val isUnread = item.manga.unread != 0
|
|
|
+ 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
|
|
@@ -143,18 +164,6 @@ class LibraryPresenter(
|
|
|
else !isCompleted
|
|
|
}
|
|
|
|
|
|
- val filterFnDownloaded: (LibraryItem) -> Boolean = downloaded@{ item ->
|
|
|
- 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.value) isDownloaded
|
|
|
- else !isDownloaded
|
|
|
- }
|
|
|
-
|
|
|
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)
|