mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 16:11:51 +01:00
refactor fav popup
This commit is contained in:
parent
198cf86377
commit
b4151e6761
@ -991,30 +991,8 @@ class MangaDetailsController : BaseController,
|
||||
if (!manga.favorite) {
|
||||
toggleMangaFavorite()
|
||||
} else {
|
||||
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
|
||||
}
|
||||
val favButton = getHeader()?.favorite_button ?: return
|
||||
val popup = makeFavPopup(favButton, manga, categories)
|
||||
popup.show()
|
||||
}
|
||||
}
|
||||
@ -1026,8 +1004,12 @@ class MangaDetailsController : BaseController,
|
||||
popupView.setOnTouchListener(null)
|
||||
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 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)
|
||||
@ -1050,7 +1032,7 @@ class MangaDetailsController : BaseController,
|
||||
}
|
||||
true
|
||||
}
|
||||
popupView.setOnTouchListener(popup.dragToOpenListener)
|
||||
return popup
|
||||
}
|
||||
|
||||
private fun toggleMangaFavorite() {
|
||||
|
Loading…
Reference in New Issue
Block a user