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

View file

@ -90,74 +90,67 @@
tools:ignore="TextContrastCheck" /> tools:ignore="TextContrastCheck" />
<LinearLayout <LinearLayout
android:id="@+id/settingsThemeContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:gravity="center"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/nav_bg_inv"
app:cardCornerRadius="16dp"
app:cardElevation="0dp">
<androidx.cardview.widget.CardView <ImageButton
android:layout_width="wrap_content" android:id="@+id/settingsUiLight"
android:layout_height="wrap_content" android:layout_width="48dp"
app:cardBackgroundColor="@color/nav_bg_inv" android:layout_height="64dp"
app:cardCornerRadius="16dp" android:alpha="0.33"
app:cardElevation="0dp"> android:background="?android:attr/selectableItemBackground"
android:src="@drawable/ic_round_brightness_high_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck,DuplicateSpeakableTextCheck" />
</androidx.cardview.widget.CardView>
<ImageButton <androidx.cardview.widget.CardView
android:id="@+id/settingsUiLight" android:layout_width="wrap_content"
android:layout_width="48dp" android:layout_height="wrap_content"
android:layout_height="64dp" app:cardBackgroundColor="@color/nav_bg_inv"
android:alpha="0.33" app:cardCornerRadius="16dp"
android:background="?android:attr/selectableItemBackground" app:cardElevation="0dp">
android:src="@drawable/ic_round_brightness_high_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck,DuplicateSpeakableTextCheck" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView <ImageButton
android:layout_width="wrap_content" android:id="@+id/settingsUiDark"
android:layout_height="wrap_content" android:layout_width="48dp"
app:cardBackgroundColor="@color/nav_bg_inv" android:layout_height="64dp"
app:cardCornerRadius="16dp" android:alpha="0.33"
app:cardElevation="0dp"> android:background="?android:attr/selectableItemBackground"
android:scaleX="-1"
android:src="@drawable/ic_round_brightness_4_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck" />
</androidx.cardview.widget.CardView>
<ImageButton <androidx.cardview.widget.CardView
android:id="@+id/settingsUiDark" android:layout_width="wrap_content"
android:layout_width="48dp" android:layout_height="wrap_content"
android:layout_height="64dp" app:cardBackgroundColor="@color/nav_bg_inv"
android:alpha="0.33" app:cardCornerRadius="16dp"
android:background="?android:attr/selectableItemBackground" app:cardElevation="0dp">
android:scaleX="-1"
android:src="@drawable/ic_round_brightness_4_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck" />
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView <ImageButton
android:layout_width="wrap_content" android:id="@+id/settingsUiAuto"
android:layout_height="wrap_content" android:layout_width="48dp"
app:cardBackgroundColor="@color/nav_bg_inv" android:layout_height="64dp"
app:cardCornerRadius="16dp" android:alpha="0.33"
app:cardElevation="0dp"> android:background="?android:attr/selectableItemBackground"
android:src="@drawable/ic_round_brightness_auto_24"
<ImageButton app:tint="?attr/colorOnBackground"
android:id="@+id/settingsUiAuto" tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck" />
android:layout_width="48dp" </androidx.cardview.widget.CardView>
android:layout_height="64dp"
android:alpha="0.33"
android:background="?android:attr/selectableItemBackground"
android:src="@drawable/ic_round_brightness_auto_24"
app:tint="?attr/colorOnBackground"
tools:ignore="ContentDescription,SpeakableTextPresentCheck,ImageContrastCheck" />
</androidx.cardview.widget.CardView>
</LinearLayout>
</LinearLayout> </LinearLayout>
@ -228,7 +221,7 @@
android:fontFamily="@font/poppins_bold" android:fontFamily="@font/poppins_bold"
android:gravity="center" android:gravity="center"
android:padding="16dp" android:padding="16dp"
android:text="Requires Android 12+" android:text="@string/requires_android_12"
android:textColor="?attr/colorSecondary" /> android:textColor="?attr/colorSecondary" />
<com.google.android.material.materialswitch.MaterialSwitch <com.google.android.material.materialswitch.MaterialSwitch
@ -768,10 +761,10 @@
android:text="@string/downloadInSd" android:text="@string/downloadInSd"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textColor="?attr/colorOnBackground" android:textColor="?attr/colorOnBackground"
android:visibility="gone"
app:cornerRadius="0dp" app:cornerRadius="0dp"
app:drawableTint="?attr/colorPrimary" app:drawableTint="?attr/colorPrimary"
app:showText="false" app:showText="false"
android:visibility="gone"
app:thumbTint="@color/button_switch_track" /> app:thumbTint="@color/button_switch_track" />
<View <View

View file

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