diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
index 99ae7cbb8..ec305d8d0 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/MangaQueries.kt
@@ -164,4 +164,14 @@ interface MangaQueries : DbProvider {
.build()
)
.prepare()
+
+ fun getChapterFetchDateManga() = db.get()
+ .listOfObjects(Manga::class.java)
+ .withQuery(
+ RawQuery.builder()
+ .query(getChapterFetchDateMangaQuery())
+ .observesTables(MangaTable.TABLE)
+ .build()
+ )
+ .prepare()
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
index 2d88c96c8..dac40b449 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/queries/RawQueries.kt
@@ -123,6 +123,16 @@ fun getLatestChapterMangaQuery() =
ORDER by max DESC
"""
+fun getChapterFetchDateMangaQuery() =
+ """
+ SELECT ${Manga.TABLE}.*, MAX(${Chapter.TABLE}.${Chapter.COL_DATE_FETCH}) AS max
+ FROM ${Manga.TABLE}
+ JOIN ${Chapter.TABLE}
+ ON ${Manga.TABLE}.${Manga.COL_ID} = ${Chapter.TABLE}.${Chapter.COL_MANGA_ID}
+ GROUP BY ${Manga.TABLE}.${Manga.COL_ID}
+ ORDER by max DESC
+"""
+
/**
* Query to get the categories for a manga.
*/
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
index 4f3cf065f..d7d280445 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt
@@ -235,6 +235,10 @@ class LibraryPresenter(
var counter = 0
db.getLatestChapterManga().executeAsBlocking().associate { it.id!! to counter++ }
}
+ val chapterFetchDateManga by lazy {
+ var counter = 0
+ db.getChapterFetchDateManga().executeAsBlocking().associate { it.id!! to counter++ }
+ }
val sortAscending = preferences.librarySortingAscending().get()
val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 ->
@@ -266,6 +270,13 @@ class LibraryPresenter(
?: latestChapterManga.size
manga1latestChapter.compareTo(manga2latestChapter)
}
+ LibrarySort.CHAPTER_FETCH_DATE -> {
+ val manga1chapterFetchDate = chapterFetchDateManga[i1.manga.id!!]
+ ?: chapterFetchDateManga.size
+ val manga2chapterFetchDate = chapterFetchDateManga[i2.manga.id!!]
+ ?: chapterFetchDateManga.size
+ manga1chapterFetchDate.compareTo(manga2chapterFetchDate)
+ }
LibrarySort.DATE_ADDED -> i2.manga.date_added.compareTo(i1.manga.date_added)
else -> throw Exception("Unknown sorting mode")
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
index 607f03f02..44ec85ae2 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt
@@ -157,11 +157,12 @@ class LibrarySettingsSheet(
private val lastChecked = Item.MultiSort(R.string.action_sort_last_checked, this)
private val unread = Item.MultiSort(R.string.action_filter_unread, this)
private val latestChapter = Item.MultiSort(R.string.action_sort_latest_chapter, this)
+ private val chapterFetchDate = Item.MultiSort(R.string.action_sort_chapter_fetch_date, this)
private val dateAdded = Item.MultiSort(R.string.action_sort_date_added, this)
override val header = null
override val items =
- listOf(alphabetically, lastRead, lastChecked, unread, total, latestChapter, dateAdded)
+ listOf(alphabetically, lastRead, lastChecked, unread, total, latestChapter, chapterFetchDate, dateAdded)
override val footer = null
override fun initModels() {
@@ -184,6 +185,8 @@ class LibrarySettingsSheet(
if (sorting == LibrarySort.TOTAL) order else Item.MultiSort.SORT_NONE
latestChapter.state =
if (sorting == LibrarySort.LATEST_CHAPTER) order else Item.MultiSort.SORT_NONE
+ chapterFetchDate.state =
+ if (sorting == LibrarySort.CHAPTER_FETCH_DATE) order else Item.MultiSort.SORT_NONE
dateAdded.state =
if (sorting == LibrarySort.DATE_ADDED) order else Item.MultiSort.SORT_NONE
}
@@ -211,6 +214,7 @@ class LibrarySettingsSheet(
unread -> LibrarySort.UNREAD
total -> LibrarySort.TOTAL
latestChapter -> LibrarySort.LATEST_CHAPTER
+ chapterFetchDate -> LibrarySort.CHAPTER_FETCH_DATE
dateAdded -> LibrarySort.DATE_ADDED
else -> throw Exception("Unknown sorting")
}
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt
index 5f6e6da8c..28e583c84 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySort.kt
@@ -8,6 +8,7 @@ object LibrarySort {
const val UNREAD = 3
const val TOTAL = 4
const val LATEST_CHAPTER = 6
+ const val CHAPTER_FETCH_DATE = 8
const val DATE_ADDED = 7
@Deprecated("Removed in favor of searching by source")
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c1bfc7fcb..7a5241411 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -42,6 +42,7 @@
Last read
Last checked
Latest chapter
+ Date fetched
Date added
Search
Search settings