From 198cf86377698634a739a7eb13875ecc203f3055 Mon Sep 17 00:00:00 2001 From: Jay Date: Sun, 9 Aug 2020 16:37:46 -0400 Subject: [PATCH] Changed long press for fav button in library inside the popup menu for said button also you can drag on the fav button to open the popup menu --- .../tachiyomi/ui/manga/MangaDetailsAdapter.kt | 1 + .../ui/manga/MangaDetailsController.kt | 86 +++++++++++++------ .../tachiyomi/ui/manga/MangaHeaderHolder.kt | 5 +- 3 files changed, 62 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt index 4618907fa3..90964874ba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsAdapter.kt @@ -123,5 +123,6 @@ class MangaDetailsAdapter( fun zoomImageFromThumb(thumbView: View) fun showTrackingSheet() fun updateScroll() + fun setFavButtonPopup(popupView: View) } } 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 af00eabddc..f7c45a7571 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 @@ -988,37 +988,71 @@ class MangaDetailsController : BaseController, if (isLocked()) return val manga = presenter.manga val categories = presenter.getCategories() - if (longPress && categories.isNotEmpty()) { - if (!manga.favorite) { - presenter.toggleFavorite() - showAddedSnack() - } - 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 - ) + if (!manga.favorite) { + toggleMangaFavorite() } else { - if (!manga.favorite) { - toggleMangaFavorite() - } else { - val headerHolder = getHeader() ?: return - val popup = PopupMenu(view!!.context, headerHolder.favorite_button) - popup.menu.add(R.string.remove_from_library) - - // Set a listener so we are notified if a menu item is clicked - popup.setOnMenuItemClickListener { - toggleMangaFavorite() - true - } - popup.show() + 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 + } + popup.show() } } + override fun setFavButtonPopup(popupView: View) { + if (isLocked()) return + val manga = presenter.manga + if (!manga.favorite) { + popupView.setOnTouchListener(null) + return + } + 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) + } + + // 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 + } + popupView.setOnTouchListener(popup.dragToOpenListener) + } + private fun toggleMangaFavorite() { if (presenter.toggleFavorite()) { val categories = presenter.getCategories() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt index 1b0964359c..ddf42f9966 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaHeaderHolder.kt @@ -71,10 +71,6 @@ class MangaHeaderHolder( favorite_button.setOnClickListener { adapter.delegate.favoriteManga(false) } - favorite_button.setOnLongClickListener { - adapter.delegate.favoriteManga(true) - true - } title.setOnClickListener { title.text?.let { adapter.delegate.globalSearch(it.toString()) } } @@ -182,6 +178,7 @@ class MangaHeaderHolder( } ) checked(!item.isLocked && manga.favorite) + adapter.delegate.setFavButtonPopup(this) } true_backdrop.setBackgroundColor( adapter.delegate.coverColor()