Long pressing library button fix

With no categories just toggle favorite status (closes #179)
This commit is contained in:
Jay 2020-04-06 03:42:23 -04:00
parent ddb4092e16
commit 7325a79318

View File

@ -966,30 +966,26 @@ class MangaDetailsController : BaseController,
override fun favoriteManga(longPress: Boolean) { override fun favoriteManga(longPress: Boolean) {
if (isLocked()) return if (isLocked()) return
val manga = presenter.manga val manga = presenter.manga
if (longPress) { val categories = presenter.getCategories()
if (longPress && categories.isNotEmpty()) {
if (!manga.favorite) { if (!manga.favorite) {
presenter.toggleFavorite() presenter.toggleFavorite()
showAddedSnack() showAddedSnack()
} }
val categories = presenter.getCategories() val ids = presenter.getMangaCategoryIds(manga)
if (categories.isEmpty()) { val preselected = ids.mapNotNull { id ->
// no categories exist, display a message about adding categories categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
snack = view?.snack(R.string.action_add_category) }.toTypedArray()
} else {
val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray()
ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected) ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected).showDialog(
.showDialog(router) router
} )
} else { } else {
if (!manga.favorite) { if (!manga.favorite) {
toggleMangaFavorite() toggleMangaFavorite()
} else { } else {
val headerHolder = recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder val headerHolder =
?: return recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder ?: return
val popup = PopupMenu(view!!.context, headerHolder.favorite_button) val popup = PopupMenu(view!!.context, headerHolder.favorite_button)
popup.menu.add(R.string.remove_from_library) popup.menu.add(R.string.remove_from_library)