offline manga order fix (again)

This commit is contained in:
Finnley Somdahl 2024-01-12 23:13:40 -06:00
parent 33bb60baad
commit 431617e6b5
3 changed files with 63 additions and 71 deletions

View file

@ -187,7 +187,8 @@ class MangaDownloaderService : Service() {
true
}
val deferredList = mutableListOf<Deferred<Bitmap?>>()
//val deferredList = mutableListOf<Deferred<Bitmap?>>()
val deferredMap = mutableMapOf<Int, Deferred<Bitmap?>>()
builder.setContentText("Downloading ${task.title} - ${task.chapter}")
if (notifi) {
notificationManager.notify(NOTIFICATION_ID, builder.build())
@ -196,13 +197,12 @@ class MangaDownloaderService : Service() {
// Loop through each ImageData object from the task
var farthest = 0
for ((index, image) in task.imageData.withIndex()) {
if (deferredList.size >= task.simultaneousDownloads) {
deferredList.awaitAll()
deferredList.clear()
if (deferredMap.size >= task.simultaneousDownloads) {
deferredMap.values.awaitAll()
deferredMap.clear()
}
val currentIndex = index // Capture the current index
val deferred = async(Dispatchers.IO) {
deferredMap[index] = async(Dispatchers.IO) {
var bitmap: Bitmap? = null
var retryCount = 0
@ -216,7 +216,7 @@ class MangaDownloaderService : Service() {
}
if (bitmap != null) {
saveToDisk("$currentIndex.jpg", bitmap, task.title, task.chapter)
saveToDisk("$index.jpg", bitmap, task.title, task.chapter)
}
farthest++
builder.setProgress(task.imageData.size, farthest, false)
@ -230,12 +230,10 @@ class MangaDownloaderService : Service() {
bitmap
}
deferredList.add(deferred)
}
// Wait for any remaining deferred to complete
deferredList.awaitAll()
deferredMap.values.awaitAll()
builder.setContentText("${task.title} - ${task.chapter} Download complete")
.setProgress(0, 0, false)

View file

@ -89,12 +89,6 @@
app:drawableEndCompat="@drawable/ic_round_arrow_drop_down_24"
tools:ignore="TextContrastCheck" />
<LinearLayout
android:id="@+id/settingsThemeContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -157,7 +151,6 @@
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout>
@ -228,7 +221,7 @@
android:fontFamily="@font/poppins_bold"
android:gravity="center"
android:padding="16dp"
android:text="Requires Android 12+"
android:text="@string/requires_android_12"
android:textColor="?attr/colorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch
@ -768,10 +761,10 @@
android:text="@string/downloadInSd"
android:textAlignment="viewStart"
android:textColor="?attr/colorOnBackground"
android:visibility="gone"
app:cornerRadius="0dp"
app:drawableTint="?attr/colorPrimary"
app:showText="false"
android:visibility="gone"
app:thumbTint="@color/button_switch_track" />
<View

View file

@ -650,5 +650,6 @@
<string name="purge_anime_downloads">Purge anime downloads</string>
<string name="purge_manga_downloads">Purge Manga Downloads</string>
<string name="purge_novel_downloads">Purge Novel Downloads</string>
<string name="requires_android_12">Requires Android 12+</string>
</resources>