From 7325a7931819987bbaf4a5d6a3cdf4c05044ea1a Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 6 Apr 2020 03:42:23 -0400 Subject: [PATCH] Long pressing library button fix With no categories just toggle favorite status (closes #179) --- .../ui/manga/MangaDetailsController.kt | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt index 3ffeca2592..77ae47d00b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsController.kt @@ -966,30 +966,26 @@ class MangaDetailsController : BaseController, override fun favoriteManga(longPress: Boolean) { if (isLocked()) return val manga = presenter.manga - if (longPress) { + val categories = presenter.getCategories() + if (longPress && categories.isNotEmpty()) { if (!manga.favorite) { presenter.toggleFavorite() 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 preselected = ids.mapNotNull { id -> - categories.indexOfFirst { it.id == id }.takeIf { it != -1 } - }.toTypedArray() + 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) - .showDialog(router) - } + ChangeMangaCategoriesDialog(this, listOf(manga), categories, preselected).showDialog( + router + ) } else { if (!manga.favorite) { toggleMangaFavorite() } else { - val headerHolder = recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder - ?: return + val headerHolder = + recycler.findViewHolderForAdapterPosition(0) as? MangaHeaderHolder ?: return val popup = PopupMenu(view!!.context, headerHolder.favorite_button) popup.menu.add(R.string.remove_from_library)