Long pressing library button fix

With no categories just toggle favorite status (closes #179)
pull/3117/head
Jay 5 years ago
parent ddb4092e16
commit 7325a79318

@ -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()
if (categories.isEmpty()) {
// no categories exist, display a message about adding categories
snack = view?.snack(R.string.action_add_category)
} else {
val ids = presenter.getMangaCategoryIds(manga) val ids = presenter.getMangaCategoryIds(manga)
val preselected = ids.mapNotNull { id -> val preselected = ids.mapNotNull { id ->
categories.indexOfFirst { it.id == id }.takeIf { it != -1 } categories.indexOfFirst { it.id == id }.takeIf { it != -1 }
}.toTypedArray() }.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)

Loading…
Cancel
Save