Skip to content

Commit

Permalink
potential fix for out of order manga downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 9, 2024
1 parent 7e5def3 commit 3d3c9fe
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3d3c9fe

Please sign in to comment.