From 7ba43ae5c283daf2aa63810d03bab04220be4ece Mon Sep 17 00:00:00 2001 From: Riztard Lanthorn Date: Fri, 14 May 2021 04:35:47 +0700 Subject: [PATCH] Add cancel all for series in download queue (#5062) Co-authored-by: Jays2Kings --- .../eu/kanade/tachiyomi/data/download/DownloadManager.kt | 9 +++++++++ .../kanade/tachiyomi/ui/download/DownloadController.kt | 9 +++++++++ .../eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt | 4 ++++ app/src/main/res/menu/download_single.xml | 3 +++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 26 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 596f02189..53a153d6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/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. * diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index e2699ccf6..a47b1c54b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/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) + } + } } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt index 7f003959e..1f8b955b1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadPresenter.kt @@ -65,4 +65,8 @@ class DownloadPresenter : BasePresenter() { fun cancelDownload(download: Download) { downloadManager.deletePendingDownload(download) } + + fun cancelDownloads(downloads: List) { + downloadManager.deletePendingDownloads(*downloads.toTypedArray()) + } } diff --git a/app/src/main/res/menu/download_single.xml b/app/src/main/res/menu/download_single.xml index b3f3e6b2f..39d0c2dc6 100644 --- a/app/src/main/res/menu/download_single.xml +++ b/app/src/main/res/menu/download_single.xml @@ -13,4 +13,7 @@ android:id="@+id/cancel_download" android:title="@string/action_cancel" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 56511bd68..4b86741cf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,7 @@ Unpin Cancel Cancel all + Cancel all for this series Sort Descending Reorder