From faa7cd3d26144f9ec4fa9230f26917f849d464c7 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 6 Apr 2020 13:30:34 -0400 Subject: [PATCH] Recents page now shows the first newest chapter in 12 hours --- .../kanade/tachiyomi/ui/recents/RecentMangaHolder.kt | 10 +++++----- .../kanade/tachiyomi/ui/recents/RecentsPresenter.kt | 12 ++++++++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt index 89c86e41ae..0ee54ce9e7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaHolder.kt @@ -47,6 +47,11 @@ class RecentMangaHolder( item.mch.manga.date_added, Date().time, DateUtils.MINUTE_IN_MILLIS ).toString() ) + item.mch.history.id == null -> body.context.getString( + R.string.updated_x, DateUtils.getRelativeTimeSpanString( + item.chapter.date_upload, Date().time, DateUtils.HOUR_IN_MILLIS + ).toString() + ) item.chapter.id != item.mch.chapter.id -> body.context.getString( if (notValidNum) R.string.last_read_x else R.string.last_read_chapter_x, if (notValidNum) item.mch.chapter.name else adapter.decimalFormat.format(item.mch.chapter.chapter_number) + @@ -54,11 +59,6 @@ class RecentMangaHolder( item.mch.history.last_read, Date().time, DateUtils.MINUTE_IN_MILLIS )})" ) - item.mch.history.id == null -> body.context.getString( - R.string.updated_x, DateUtils.getRelativeTimeSpanString( - item.chapter.date_upload, Date().time, DateUtils.HOUR_IN_MILLIS - ).toString() - ) !isSearch && item.chapter.pages_left > 0 -> itemView.resources.getQuantityString( R.plurals.pages_left, item.chapter.pages_left, item.chapter.pages_left ) + diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt index b228143ea1..84f324df6c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt @@ -80,7 +80,8 @@ class RecentsPresenter( } val pairs = mangaList.mapNotNull { val chapter = if (it.chapter.read || it.chapter.id == null) getNextChapter(it.manga) - else it.chapter + else if (it.history.id == null) getFirstUpdatedChapter(it.manga, it.chapter) + else it.chapter if (chapter == null) if (query.isNotEmpty() && it.chapter.id != null) Pair( it, it.chapter ) @@ -92,7 +93,7 @@ class RecentsPresenter( pairs.filter { it.first.history.id == null && it.first.chapter.id != null } .sortedWith(Comparator> { f1, f2 -> if (abs(f1.second.date_fetch - f2.second.date_fetch) <= - TimeUnit.HOURS.toMillis(2)) + TimeUnit.HOURS.toMillis(12)) f2.second.date_upload.compareTo(f1.second.date_upload) else f2.second.date_fetch.compareTo(f1.second.date_fetch) @@ -132,6 +133,13 @@ class RecentsPresenter( return chapters.sortedByDescending { it.source_order }.find { !it.read } } + private fun getFirstUpdatedChapter(manga: Manga, chapter: Chapter): Chapter? { + val chapters = db.getChapters(manga).executeAsBlocking() + return chapters.sortedByDescending { it.source_order }.find { + !it.read && abs(it.date_fetch - chapter.date_fetch) <= TimeUnit.HOURS.toMillis(12) + } + } + fun onDestroy() { downloadManager.removeListener(this) LibraryUpdateService.removeListener(this)