Skip to content

Commit

Permalink
offline manga order fix (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 13, 2024
1 parent 33bb60b commit 431617e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand Down
123 changes: 58 additions & 65 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,74 +90,67 @@
tools:ignore="TextContrastCheck" />

<LinearLayout
android:id="@+id/settingsThemeContainer"
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">

<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
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/nav_bg_inv"
app:cardCornerRadius="16dp"
app:cardElevation="0dp">

<ImageButton
android:id="@+id/settingsUiLight"
android:layout_width="48dp"
android:layout_height="64dp"
android:alpha="0.33"
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>

<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">

<ImageButton
android:id="@+id/settingsUiDark"
android:layout_width="48dp"
android:layout_height="64dp"
android:alpha="0.33"
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>

<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">

<ImageButton
android:id="@+id/settingsUiAuto"
android:layout_width="48dp"
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>
<ImageButton
android:id="@+id/settingsUiLight"
android:layout_width="48dp"
android:layout_height="64dp"
android:alpha="0.33"
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>

<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">

<ImageButton
android:id="@+id/settingsUiDark"
android:layout_width="48dp"
android:layout_height="64dp"
android:alpha="0.33"
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>

<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">

<ImageButton
android:id="@+id/settingsUiAuto"
android:layout_width="48dp"
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>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit 431617e

Please sign in to comment.