From 5fa9d211aa367c5d2414cd16453612b5e7c91437 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 28 Apr 2020 16:33:19 -0400 Subject: [PATCH] Fixed issue with canceling a downloading in manga details when there's more downloads --- .../ui/manga/MangaDetailsController.kt | 2 +- .../ui/manga/MangaDetailsPresenter.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 8ffc357aeb..714295d87e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -1058,7 +1058,7 @@ class MangaDetailsController : BaseController, return } if (chapter.status != Download.NOT_DOWNLOADED && chapter.status != Download.ERROR) { - presenter.deleteChapters(listOf(chapter)) + presenter.deleteChapter(chapter) } else { if (chapter.status == Download.ERROR) DownloadService.start(view.context) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index 75d457a32a..dedb3f7f07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -340,6 +340,24 @@ class MangaDetailsPresenter( downloadManager.downloadChapters(manga, chapters.filter { !it.isDownloaded }) } + /** + * Deletes the given list of chapter. + * @param chapter the chapter to delete. + */ + fun deleteChapter(chapter: ChapterItem) { + downloadManager.deleteChapters(listOf(chapter), manga, source) + val downloads = downloadManager.queue.toMutableList() + downloads.remove(chapter.download) + downloadManager.reorderQueue(downloads) + + this.chapters.find { it.id == chapter.id }?.apply { + status = Download.NOT_DOWNLOADED + download = null + } + + controller.updateChapters(this.chapters) + } + /** * Deletes the given list of chapter. * @param chapters the list of chapters to delete.