Fix stucked downloads when service not started (#7846)

* Fix stucked downloads when service not started

* Fix chapter download restart even if should be deleted

(cherry picked from commit a70b8486468ce8b57ae7a7ddc3ac845337789d45)
This commit is contained in:
nzoba 2022-08-24 23:18:22 +02:00 committed by Jobobby04
parent 77245074e8
commit a024d8810c
2 changed files with 4 additions and 2 deletions

View File

@ -165,12 +165,12 @@ class DownloadManager(
* @param downloads the list of downloads to enqueue. * @param downloads the list of downloads to enqueue.
*/ */
fun addDownloadsToStartOfQueue(downloads: List<Download>) { fun addDownloadsToStartOfQueue(downloads: List<Download>) {
val wasEmpty = queue.isEmpty() if (downloads.isEmpty()) return
queue.toMutableList().apply { queue.toMutableList().apply {
addAll(0, downloads) addAll(0, downloads)
reorderQueue(this) reorderQueue(this)
} }
if (wasEmpty) startDownloads() if (!DownloadService.isRunning(context)) DownloadService.start(context)
} }
/** /**

View File

@ -597,6 +597,8 @@ class ReaderPresenter(
if (removeAfterReadSlots != 0 && chapterDownload != null) { if (removeAfterReadSlots != 0 && chapterDownload != null) {
downloadManager.addDownloadsToStartOfQueue(listOf(chapterDownload!!)) downloadManager.addDownloadsToStartOfQueue(listOf(chapterDownload!!))
} else {
chapterDownload = null
} }
// Check if deleting option is enabled and chapter exists // Check if deleting option is enabled and chapter exists
if (removeAfterReadSlots != -1 && chapterToDelete != null) { if (removeAfterReadSlots != -1 && chapterToDelete != null) {