From 3d3c9feaecb903b4893ac8c1cc1e3ec99309f7a8 Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Tue, 9 Jan 2024 06:34:51 -0600 Subject: [PATCH] potential fix for out of order manga downloads --- .../ani/dantotsu/download/manga/MangaDownloaderService.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/download/manga/MangaDownloaderService.kt b/app/src/main/java/ani/dantotsu/download/manga/MangaDownloaderService.kt index 202a4b8f11..ecf223bff1 100644 --- a/app/src/main/java/ani/dantotsu/download/manga/MangaDownloaderService.kt +++ b/app/src/main/java/ani/dantotsu/download/manga/MangaDownloaderService.kt @@ -196,14 +196,12 @@ class MangaDownloaderService : Service() { // Loop through each ImageData object from the task var farthest = 0 for ((index, image) in task.imageData.withIndex()) { - // Limit the number of simultaneous downloads from the task if (deferredList.size >= task.simultaneousDownloads) { - // Wait for all deferred to complete and clear the list deferredList.awaitAll() deferredList.clear() } - // Download the image and add to deferred list + val currentIndex = index // Capture the current index val deferred = async(Dispatchers.IO) { var bitmap: Bitmap? = null var retryCount = 0 @@ -217,9 +215,8 @@ class MangaDownloaderService : Service() { retryCount++ } - // Cache the image if successful if (bitmap != null) { - saveToDisk("$index.jpg", bitmap, task.title, task.chapter) + saveToDisk("$currentIndex.jpg", bitmap, task.title, task.chapter) } farthest++ builder.setProgress(task.imageData.size, farthest, false)