From 780585caed7b4fa933fc5e55236af110e68ca689 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sun, 11 Apr 2021 12:34:52 -0400 Subject: [PATCH] Crash fixes in recents --- .../eu/kanade/tachiyomi/ui/recents/RecentMangaItem.kt | 2 +- .../eu/kanade/tachiyomi/ui/recents/RecentsPresenter.kt | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaItem.kt index 5f1067c336..a6f13fdf54 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentMangaItem.kt @@ -61,6 +61,6 @@ class RecentMangaItem( val showRemoveHistory = (adapter as? RecentMangaAdapter)?.showRemoveHistory ?: true val showTitleFirst = (adapter as? RecentMangaAdapter)?.showTitleFirst ?: false if (mch.manga.id == null) (holder as? RecentMangaFooterHolder)?.bind((header as? RecentMangaHeaderItem)?.recentsType ?: 0) - else (holder as? RecentMangaHolder)?.bind(this, showDLs, showRemoveHistory, showTitleFirst) + else if (chapter.id != null) (holder as? RecentMangaHolder)?.bind(this, showDLs, showRemoveHistory, showTitleFirst) } } 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 59f510ba22..f6eaa81a05 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 @@ -40,6 +40,7 @@ class RecentsPresenter( private var scope = CoroutineScope(Job() + Dispatchers.Default) + private var recentsJob: Job? = null var recentItems = listOf() private set var query = "" @@ -88,10 +89,11 @@ class RecentsPresenter( getRecents() } - fun getRecents(updatePageCount: Boolean = false, retryCount: Int = 0, itemCount: Int = 0) { + fun getRecents(updatePageCount: Boolean = false) { val oldQuery = query - scope.launch { - runRecents(oldQuery, updatePageCount, retryCount, itemCount) + recentsJob?.cancel() + recentsJob = scope.launch { + runRecents(oldQuery, updatePageCount) } } @@ -320,7 +322,7 @@ class RecentsPresenter( * @param chapters the list of chapter from the database. */ private fun setDownloadedChapters(chapters: List) { - for (item in chapters) { + for (item in chapters.filter { it.chapter.id != null }) { if (downloadManager.isChapterDownloaded(item.chapter, item.mch.manga)) { item.status = Download.DOWNLOADED } else if (downloadManager.hasQueue()) {