瀏覽代碼

Add cancel all for series in download queue (#5062)

Co-authored-by: Jays2Kings <[email protected]>
Riztard Lanthorn 3 年之前
父節點
當前提交
7ba43ae5c2

+ 9 - 0
app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt

@@ -203,6 +203,15 @@ class DownloadManager(private val context: Context) {
         deleteChapters(listOf(download.chapter), download.manga, download.source)
     }
 
+    fun deletePendingDownloads(vararg downloads: Download) {
+        val downloadsByManga = downloads.groupBy { it.manga.id }
+        downloadsByManga.map { entry ->
+            val manga = entry.value.first().manga
+            val source = entry.value.first().source
+            deleteChapters(entry.value.map { it.chapter }, manga, source)
+        }
+    }
+
     /**
      * Deletes the directories of a list of downloaded chapters.
      *

+ 9 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt

@@ -356,6 +356,15 @@ class DownloadController :
                 val downloads = adapter.currentItems.mapNotNull { it?.download }
                 presenter.reorder(downloads)
             }
+            R.id.cancel_series -> {
+                val download = adapter?.getItem(position)?.download ?: return
+                val allDownloadsForSeries = adapter?.currentItems
+                    ?.filter { download.manga.id == it.download.manga.id }
+                    ?.map(DownloadItem::download)
+                if (!allDownloadsForSeries.isNullOrEmpty()) {
+                    presenter.cancelDownloads(allDownloadsForSeries)
+                }
+            }
         }
     }
 }

+ 4 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt

@@ -65,4 +65,8 @@ class DownloadPresenter : BasePresenter<DownloadController>() {
     fun cancelDownload(download: Download) {
         downloadManager.deletePendingDownload(download)
     }
+
+    fun cancelDownloads(downloads: List<Download>) {
+        downloadManager.deletePendingDownloads(*downloads.toTypedArray())
+    }
 }

+ 3 - 0
app/src/main/res/menu/download_single.xml

@@ -13,4 +13,7 @@
         android:id="@+id/cancel_download"
         android:title="@string/action_cancel" />
 
+    <item android:id="@+id/cancel_series"
+        android:title="@string/cancel_all_for_series" />
+
 </menu>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -102,6 +102,7 @@
     <string name="action_unpin">Unpin</string>
     <string name="action_cancel">Cancel</string>
     <string name="action_cancel_all">Cancel all</string>
+    <string name="cancel_all_for_series">Cancel all for this series</string>
     <string name="action_sort">Sort</string>
     <string name="action_sort_descending">Descending</string>
     <string name="action_reorganize_by">Reorder</string>