Changed long press for fav button in library inside the popup menu for said button

also you can drag on the fav button to open the popup menu
This commit is contained in:
Jay 2020-08-09 16:37:46 -04:00
parent 0670e00a09
commit 198cf86377
3 changed files with 62 additions and 30 deletions

View File

@ -123,5 +123,6 @@ class MangaDetailsAdapter(
fun zoomImageFromThumb(thumbView: View)
fun showTrackingSheet()
fun updateScroll()
fun setFavButtonPopup(popupView: View)
}
}

View File

@ -988,37 +988,71 @@ class MangaDetailsController : BaseController,
if (isLocked()) return
val manga = presenter.manga
val categories = presenter.getCategories()
if (longPress && categories.isNotEmpty()) {
if (!manga.favorite) {
presenter.toggleFavorite()
showAddedSnack()
}
val ids = presenter.getMangaCategoryIds()
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected).showDialog(
router
)
if (!manga.favorite) {
toggleMangaFavorite()
} else {
if (!manga.favorite) {
toggleMangaFavorite()
} else {
val headerHolder = getHeader() ?: return
val popup = PopupMenu(view!!.context, headerHolder.favorite_button)
popup.menu.add(R.string.remove_from_library)
// Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener {
toggleMangaFavorite()
true
}
popup.show()
val headerHolder = getHeader() ?: return
val popup = PopupMenu(view!!.context, headerHolder.favorite_button)
popup.menu.add(0, 1, 0, R.string.remove_from_library)
if (categories.isNotEmpty()) {
popup.menu.add(0, 0, 1, R.string.edit_categories)
}
// Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener { menuItem ->
if (menuItem.itemId == 0) {
val ids = presenter.getMangaCategoryIds()
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(
this, listOf(manga), categories, preselected
).showDialog(
router
)
} else {
toggleMangaFavorite()
}
true
}
popup.show()
}
}
override fun setFavButtonPopup(popupView: View) {
if (isLocked()) return
val manga = presenter.manga
if (!manga.favorite) {
popupView.setOnTouchListener(null)
return
}
val popup = PopupMenu(view!!.context, popupView)
val categories = presenter.getCategories()
popup.menu.add(0, 1, 0, R.string.remove_from_library)
if (categories.isNotEmpty()) {
popup.menu.add(0, 0, 1, R.string.edit_categories)
}
// Set a listener so we are notified if a menu item is clicked
popup.setOnMenuItemClickListener { menuItem ->
if (menuItem.itemId == 0) {
val ids = presenter.getMangaCategoryIds()
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(
this, listOf(manga), categories, preselected
).showDialog(
router
)
} else {
toggleMangaFavorite()
}
true
}
popupView.setOnTouchListener(popup.dragToOpenListener)
}
private fun toggleMangaFavorite() {
if (presenter.toggleFavorite()) {
val categories = presenter.getCategories()

View File

@ -71,10 +71,6 @@ class MangaHeaderHolder(
favorite_button.setOnClickListener {
adapter.delegate.favoriteManga(false)
}
favorite_button.setOnLongClickListener {
adapter.delegate.favoriteManga(true)
true
}
title.setOnClickListener {
title.text?.let { adapter.delegate.globalSearch(it.toString()) }
}
@ -182,6 +178,7 @@ class MangaHeaderHolder(
}
)
checked(!item.isLocked && manga.favorite)
adapter.delegate.setFavButtonPopup(this)
}
true_backdrop.setBackgroundColor(
adapter.delegate.coverColor()