Add cover actions to a dialog when long-pressing manga cover (#5556)

This commit is contained in:
Hunter Nickel 2021-07-15 15:28:35 -06:00 committed by GitHub
parent 4ce4ee3c00
commit a1e83b9f19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View file

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

View file

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