From a70b8486468ce8b57ae7a7ddc3ac845337789d45 Mon Sep 17 00:00:00 2001 From: nzoba <55888232+nzoba@users.noreply.github.com> Date: Wed, 24 Aug 2022 23:18:22 +0200 Subject: [PATCH] Fix stucked downloads when service not started (#7846) * Fix stucked downloads when service not started * Fix chapter download restart even if should be deleted --- .../java/eu/kanade/tachiyomi/data/download/DownloadManager.kt | 4 ++-- .../java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) 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 374d92623..4297a4546 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 @@ -163,12 +163,12 @@ class DownloadManager( * @param downloads the list of downloads to enqueue. */ fun addDownloadsToStartOfQueue(downloads: List) { - val wasEmpty = queue.isEmpty() + if (downloads.isEmpty()) return queue.toMutableList().apply { addAll(0, downloads) reorderQueue(this) } - if (wasEmpty) startDownloads() + if (!DownloadService.isRunning(context)) DownloadService.start(context) } /** 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 3095bf84a..d7b595f5c 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 @@ -500,6 +500,8 @@ class ReaderPresenter( if (removeAfterReadSlots != 0 && chapterDownload != null) { downloadManager.addDownloadsToStartOfQueue(listOf(chapterDownload!!)) + } else { + chapterDownload = null } // Check if deleting option is enabled and chapter exists if (removeAfterReadSlots != -1 && chapterToDelete != null) {