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

Co-authored-by: Jays2Kings <jays@outlook.com>
This commit is contained in:
Riztard Lanthorn 2021-05-14 04:35:47 +07:00 committed by GitHub
parent 5700c7a0c7
commit 7ba43ae5c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 0 deletions

View File

@ -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.
*

View File

@ -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)
}
}
}
}
}

View File

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

View File

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

View File

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