mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 15:41:52 +01:00
refactor fav popup
This commit is contained in:
parent
198cf86377
commit
b4151e6761
@ -991,30 +991,8 @@ class MangaDetailsController : BaseController,
|
|||||||
if (!manga.favorite) {
|
if (!manga.favorite) {
|
||||||
toggleMangaFavorite()
|
toggleMangaFavorite()
|
||||||
} else {
|
} else {
|
||||||
val headerHolder = getHeader() ?: return
|
val favButton = getHeader()?.favorite_button ?: return
|
||||||
val popup = PopupMenu(view!!.context, headerHolder.favorite_button)
|
val popup = makeFavPopup(favButton, manga, categories)
|
||||||
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()
|
popup.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1026,8 +1004,12 @@ class MangaDetailsController : BaseController,
|
|||||||
popupView.setOnTouchListener(null)
|
popupView.setOnTouchListener(null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
val popup = makeFavPopup(popupView, manga, presenter.getCategories())
|
||||||
|
popupView.setOnTouchListener(popup.dragToOpenListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun makeFavPopup(popupView: View, manga: Manga, categories: List<Category>): PopupMenu {
|
||||||
val popup = PopupMenu(view!!.context, popupView)
|
val popup = PopupMenu(view!!.context, popupView)
|
||||||
val categories = presenter.getCategories()
|
|
||||||
popup.menu.add(0, 1, 0, R.string.remove_from_library)
|
popup.menu.add(0, 1, 0, R.string.remove_from_library)
|
||||||
if (categories.isNotEmpty()) {
|
if (categories.isNotEmpty()) {
|
||||||
popup.menu.add(0, 0, 1, R.string.edit_categories)
|
popup.menu.add(0, 0, 1, R.string.edit_categories)
|
||||||
@ -1050,7 +1032,7 @@ class MangaDetailsController : BaseController,
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
popupView.setOnTouchListener(popup.dragToOpenListener)
|
return popup
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleMangaFavorite() {
|
private fun toggleMangaFavorite() {
|
||||||
|
Loading…
Reference in New Issue
Block a user