From 11ab3b2c2e906e51cd27c57cc7a7ed2deb188867 Mon Sep 17 00:00:00 2001 From: Andreas E Date: Sat, 3 Oct 2020 18:29:51 +0200 Subject: [PATCH] Remove from queue after read (#3870) * Add option to remove chapter from download queue after marked as read * Begone bug There was a bug when one queued a new download to the downloader. Which resulted in getChapterDownloadOrNull() would not find the corresponding download for the provided chapter * Fix review comment * Remove preference and just remove from queue --- .../kanade/tachiyomi/data/download/DownloadManager.kt | 11 +++++++++++ .../eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 400fe56482..ac2df1ee96 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -173,6 +173,17 @@ class DownloadManager(private val context: Context) { return cache.isChapterDownloaded(chapter, manga, skipCache) } + /** + * Returns the download from queue if the chapter is queued for download + * else it will return null which means that the chapter is not queued for download + * + * @param chapter the chapter to check. + */ + fun getChapterDownloadOrNull(chapter: Chapter): Download? { + return downloader.queue + .firstOrNull { it.chapter.id == chapter.id && it.chapter.manga_id == chapter.manga_id } + } + /** * Returns the amount of downloaded chapters for a manga. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index 1ec3cd1aff..7068022621 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -361,6 +361,7 @@ class ReaderPresenter( selectedChapter.chapter.read = true updateTrackChapterRead(selectedChapter) deleteChapterIfNeeded(selectedChapter) + deleteChapterFromDownloadQueue(currentChapters.currChapter) } if (selectedChapter != currentChapters.currChapter) { @@ -370,6 +371,16 @@ class ReaderPresenter( } } + /** + * Removes [currentChapter] from download queue + * if setting is enabled and [currentChapter] is queued for download + */ + private fun deleteChapterFromDownloadQueue(currentChapter: ReaderChapter) { + downloadManager.getChapterDownloadOrNull(currentChapter.chapter)?.let { download -> + downloadManager.deletePendingDownload(download) + } + } + /** * Determines if deleting option is enabled and nth to last chapter actually exists. * If both conditions are satisfied enqueues chapter for delete