From 5002692bda658354f1df6285cade002b29747d59 Mon Sep 17 00:00:00 2001 From: CVIUS <84634607+CVIUS@users.noreply.github.com> Date: Sat, 14 May 2022 23:37:47 +0800 Subject: [PATCH] Add long click action on chapter download button (#7125) --- .../tachiyomi/ui/manga/chapter/ChapterHolder.kt | 4 ++++ .../ui/manga/chapter/base/BaseChapterHolder.kt | 16 ++++++++++++++++ .../tachiyomi/ui/recent/updates/UpdatesHolder.kt | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt index 13edc1574..18d3f7621 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterHolder.kt @@ -25,6 +25,10 @@ class ChapterHolder( binding.download.setOnClickListener { onDownloadClick(it, bindingAdapterPosition) } + binding.download.setOnLongClickListener { + onDownloadLongClick(bindingAdapterPosition) + true + } } fun bind(item: ChapterItem, manga: Manga) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChapterHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChapterHolder.kt index a3a38dd43..e2f1dcc9c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChapterHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/base/BaseChapterHolder.kt @@ -41,4 +41,20 @@ open class BaseChapterHolder( } } } + + fun onDownloadLongClick(position: Int) { + val item = adapter.getItem(position) as? BaseChapterItem<*, *> ?: return + when (item.status) { + Download.State.NOT_DOWNLOADED, Download.State.ERROR -> { + adapter.clickListener.downloadChapter(position) + } + Download.State.DOWNLOADED, Download.State.DOWNLOADING -> { + adapter.clickListener.deleteChapter(position) + } + // Download.State.QUEUE + else -> { + adapter.clickListener.startDownloadNow(position) + } + } + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt index 25f2c4dd6..e669fafce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesHolder.kt @@ -30,6 +30,10 @@ class UpdatesHolder(private val view: View, private val adapter: UpdatesAdapter) binding.download.setOnClickListener { onDownloadClick(it, bindingAdapterPosition) } + binding.download.setOnLongClickListener { + onDownloadLongClick(bindingAdapterPosition) + true + } } fun bind(item: UpdatesItem) {