diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt index 93430df3ae..e59a744bc3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Category.kt @@ -42,6 +42,7 @@ interface Category : Serializable { TOTAL_ASC, TOTAL_DSC -> LibrarySort.TOTAL DRAG_AND_DROP -> LibrarySort.DRAG_AND_DROP DATE_ADDED_ASC, DATE_ADDED_DSC -> LibrarySort.DATE_ADDED + LAST_FETCHED_ASC, LAST_FETCHED_DSC -> LibrarySort.LAST_FETCHED else -> if (nullAsDND && !isDynamic) LibrarySort.DRAG_AND_DROP else null } @@ -55,6 +56,7 @@ interface Category : Serializable { LAST_READ_ASC, LAST_READ_DSC -> R.string.last_read TOTAL_ASC, TOTAL_DSC -> R.string.total_chapters DATE_ADDED_ASC, DATE_ADDED_DSC -> R.string.date_added + LAST_FETCHED_ASC, LAST_FETCHED_DSC -> R.string.last_fetched else -> if (isDynamic) R.string.category else R.string.drag_and_drop } @@ -65,6 +67,7 @@ interface Category : Serializable { LAST_READ_ASC, LAST_READ_DSC -> 3 TOTAL_ASC, TOTAL_DSC -> 4 DATE_ADDED_ASC, DATE_ADDED_DSC -> 5 + LAST_FETCHED_ASC, LAST_FETCHED_DSC -> 6 else -> null } @@ -76,6 +79,7 @@ interface Category : Serializable { LibrarySort.LAST_READ -> LAST_READ_ASC LibrarySort.TOTAL -> ALPHA_ASC LibrarySort.DATE_ADDED -> DATE_ADDED_ASC + LibrarySort.LAST_FETCHED -> LAST_FETCHED_ASC else -> ALPHA_ASC } } @@ -94,6 +98,8 @@ interface Category : Serializable { const val TOTAL_DSC = 'j' const val DATE_ADDED_ASC = 'k' const val DATE_ADDED_DSC = 'l' + const val LAST_FETCHED_ASC = 'm' + const val LAST_FETCHED_DSC = 'n' fun create(name: String): Category = CategoryImpl().apply { this.name = name @@ -113,6 +119,7 @@ interface Category : Serializable { LibrarySort.LAST_READ -> LAST_READ_ASC LibrarySort.TOTAL -> TOTAL_ASC LibrarySort.DATE_ADDED -> DATE_ADDED_ASC + LibrarySort.LAST_FETCHED -> LAST_FETCHED_ASC LibrarySort.DRAG_AND_DROP -> DRAG_AND_DROP else -> DRAG_AND_DROP } 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 4127ec0f58..3a1c0799b6 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 @@ -146,6 +146,16 @@ interface MangaQueries : DbProvider { ) .prepare() + fun getLastFetchedManga() = db.get() + .listOfObjects(Manga::class.java) + .withQuery( + RawQuery.builder() + .query(getLastFetchedMangaQuery()) + .observesTables(MangaTable.TABLE) + .build() + ) + .prepare() + fun getTotalChapterManga() = db.get().listOfObjects(Manga::class.java) .withQuery(RawQuery.builder().query(getTotalChapterMangaQuery()).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 bdc1b4c88a..e698fe107a 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 @@ -276,6 +276,17 @@ fun getLastReadMangaQuery() = ORDER BY max DESC """ +fun getLastFetchedMangaQuery() = + """ + 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} + WHERE ${Manga.TABLE}.${Manga.COL_FAVORITE} = 1 + GROUP BY ${Manga.TABLE}.${Manga.COL_ID} + ORDER BY max DESC +""" + fun getTotalChapterMangaQuery() = """ SELECT ${Manga.TABLE}.* diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt index ce824024a8..d65ad87475 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/MaterialMenuSheet.kt @@ -130,8 +130,10 @@ class MaterialMenuSheet( if (clearAll) { clearEndDrawables() } - itemAdapter.getAdapterItem(id).sheetItem.endDrawableRes = drawableRes - itemAdapter.getAdapterItem(id).isSelected = true + val pos = itemAdapter.getAdapterPosition(id.toLong()) + val item = itemAdapter.getAdapterItem(pos) + item.sheetItem.endDrawableRes = drawableRes + item.isSelected = true fastAdapter.notifyAdapterDataSetChanged() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt index 927d4db647..a4363341fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryAdapter.kt @@ -150,14 +150,27 @@ class LibraryCategoryAdapter(val controller: LibraryController) : else title.take(10) } } + LibrarySort.LAST_FETCHED -> { + val id = item.manga.id ?: return "" + val history = db.getChapters(id).executeAsBlocking() + val last = history.maxOfOrNull { it.date_fetch } + if (last != null && last > 100) { + recyclerView.context.getString( + R.string.fetched_, + last.timeSpanFromNow(preferences.context) + ) + } else { + "N/A" + } + } LibrarySort.LAST_READ -> { val id = item.manga.id ?: return "" val history = db.getHistoryByMangaId(id).executeAsBlocking() - val last = history.maxBy { it.last_read } - if (last != null && last.last_read > 100) { + val last = history.maxOfOrNull { it.last_read } + if (last != null && last > 100) { recyclerView.context.getString( R.string.read_, - last.last_read.timeSpanFromNow(preferences.context) + last.timeSpanFromNow(preferences.context) ) } else { "N/A" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt index 1119fcbd5c..7577e81ab0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryHeaderHolder.kt @@ -92,7 +92,11 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd val sortingMode = category.sortingMode() val sortDrawable = when { sortingMode == LibrarySort.DRAG_AND_DROP || sortingMode == null -> R.drawable.ic_sort_24dp - if (sortingMode == LibrarySort.DATE_ADDED || sortingMode == LibrarySort.LATEST_CHAPTER || sortingMode == LibrarySort.LAST_READ) !isAscending else isAscending -> R.drawable.ic_arrow_downward_24dp + if (sortingMode == LibrarySort.DATE_ADDED || + sortingMode == LibrarySort.LATEST_CHAPTER || + sortingMode == LibrarySort.LAST_READ || + sortingMode == LibrarySort.LAST_FETCHED + ) !isAscending else isAscending -> R.drawable.ic_arrow_downward_24dp else -> R.drawable.ic_arrow_upward_24dp } @@ -158,6 +162,11 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd R.drawable.ic_new_releases_24dp, R.string.latest_chapter ), + MaterialMenuSheet.MenuSheetItem( + LibrarySort.LAST_FETCHED, + R.drawable.ic_check_24dp, + R.string.last_fetched + ), MaterialMenuSheet.MenuSheetItem( LibrarySort.UNREAD, R.drawable.ic_eye_24dp, @@ -216,7 +225,8 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd sortingMode == LibrarySort.DRAG_AND_DROP -> R.drawable.ic_check_24dp if (sortingMode == LibrarySort.DATE_ADDED || sortingMode == LibrarySort.LATEST_CHAPTER || - sortingMode == LibrarySort.LAST_READ + sortingMode == LibrarySort.LAST_READ || + sortingMode == LibrarySort.LAST_FETCHED ) !isAscending else isAscending -> R.drawable.ic_arrow_downward_24dp else -> R.drawable.ic_arrow_upward_24dp @@ -233,6 +243,7 @@ class LibraryHeaderHolder(val view: View, private val adapter: LibraryCategoryAd adapter.libraryListener.sortCategory(category.id!!, 'D' - 'a' + 1) return } + LibrarySort.LAST_FETCHED -> 6 LibrarySort.DATE_ADDED -> 5 LibrarySort.TOTAL -> 4 LibrarySort.LAST_READ -> 3 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 a8d7b1cdee..f004af8b03 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 @@ -343,6 +343,11 @@ class LibraryPresenter( db.getLastReadManga().executeAsBlocking().associate { it.id!! to counter++ } } + val lastFetchedManga by lazy { + var counter = 0 + db.getLastFetchedManga().executeAsBlocking().associate { it.id!! to counter++ } + } + val sortFn: (LibraryItem, LibraryItem) -> Int = { i1, i2 -> if (i1.header.category.id == i2.header.category.id) { val category = i1.header.category @@ -371,6 +376,11 @@ class LibraryPresenter( LibrarySort.TOTAL -> { i1.manga.totalChapters.compareTo(i2.manga.totalChapters) } + LibrarySort.LAST_FETCHED -> { + val manga1LastRead = lastFetchedManga[i1.manga.id!!] ?: lastFetchedManga.size + val manga2LastRead = lastFetchedManga[i2.manga.id!!] ?: lastFetchedManga.size + manga1LastRead.compareTo(manga2LastRead) + } LibrarySort.DATE_ADDED -> i2.manga.date_added.compareTo(i1.manga.date_added) else -> { if (LibrarySort.DRAG_AND_DROP == category.sortingMode() && category.isDynamic) { 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 3ad22861c8..0506561ac9 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,5 +8,6 @@ object LibrarySort { const val UNREAD = 3 const val TOTAL = 4 const val DATE_ADDED = 5 - const val DRAG_AND_DROP = 6 + const val LAST_FETCHED = 6 + const val DRAG_AND_DROP = 7 } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4efbeeffc9..8270d78a89 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -146,6 +146,7 @@ Total chapters Date added Last read + Last fetched Last Updated Latest chapter Drag & Drop