From a1e83b9f19844b8590d637f024cb2ee6550f6765 Mon Sep 17 00:00:00 2001 From: Hunter Nickel Date: Thu, 15 Jul 2021 15:28:35 -0600 Subject: [PATCH] Add cover actions to a dialog when long-pressing manga cover (#5556) --- .../tachiyomi/ui/manga/MangaController.kt | 6 ++--- .../ui/manga/info/MangaInfoHeaderAdapter.kt | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index e0a61591a..9c858713c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -661,7 +661,7 @@ class MangaController : } } - private fun shareCover() { + fun shareCover() { try { val activity = activity!! val cover = presenter.shareCover(activity) @@ -673,7 +673,7 @@ class MangaController : } } - private fun saveCover() { + fun saveCover() { try { presenter.saveCover(activity!!) activity?.toast(R.string.cover_saved) @@ -683,7 +683,7 @@ class MangaController : } } - private fun changeCover() { + fun changeCover() { val manga = manga ?: return if (manga.hasCustomCover(coverCache)) { ChangeMangaCoverDialog(this, manga).showDialog(router) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt index 2eda69ac9..d6777d89f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoHeaderAdapter.kt @@ -6,6 +6,7 @@ import android.view.ViewGroup import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView import coil.loadAny +import com.google.android.material.dialog.MaterialAlertDialogBuilder import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.track.TrackManager @@ -177,16 +178,34 @@ class MangaInfoHeaderAdapter( binding.mangaCover.longClicks() .onEach { - controller.activity?.copyToClipboard( - view.context.getString(R.string.title), - controller.presenter.manga.title - ) + showCoverOptionsDialog() } .launchIn(controller.viewScope) setMangaInfo(manga, source) } + private fun showCoverOptionsDialog() { + val options = listOfNotNull( + R.string.action_share, + R.string.action_save, + // Can only edit cover for library manga + if (manga.favorite) R.string.action_edit else null + ).map(controller.activity!!::getString).toTypedArray() + + MaterialAlertDialogBuilder(controller.activity!!) + .setTitle(R.string.manga_cover) + .setItems(options) { _, item -> + when (item) { + 0 -> controller.shareCover() + 1 -> controller.saveCover() + 2 -> controller.changeCover() + } + } + .setNegativeButton(android.R.string.cancel, null) + .show() + } + /** * Update the view with manga information. *