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 35bb6e6410..44ce398111 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 @@ -178,6 +178,7 @@ class MangaDetailsController : BaseController, private var textAnim: ViewPropertyAnimator? = null private var scrollAnim: ViewPropertyAnimator? = null var isTablet = false + var chapterPopupMenu: Pair? = null // Tablet Layout var tabletRecycler: RecyclerView? = null @@ -647,6 +648,7 @@ class MangaDetailsController : BaseController, val item = (adapter.getItem(position) as? ChapterItem) ?: return val itemView = getHolder(item)?.itemView ?: return val popup = PopupMenu(itemView.context, itemView) + chapterPopupMenu = position to popup // Inflate our menu resource into the PopupMenu's Menu popup.menuInflater.inflate(R.menu.chapter_single, popup.menu) @@ -656,6 +658,7 @@ class MangaDetailsController : BaseController, when (menuItem.itemId) { R.id.action_mark_previous_as_read -> markPreviousAsRead(item) } + chapterPopupMenu = null true } @@ -663,6 +666,13 @@ class MangaDetailsController : BaseController, popup.show() } + fun dismissPopup(position: Int) { + if (chapterPopupMenu != null && chapterPopupMenu?.first == position) { + chapterPopupMenu?.second?.dismiss() + chapterPopupMenu = null + } + } + private fun markPreviousAsRead(chapter: ChapterItem) { val adapter = adapter ?: return val chapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterItem.kt index e71316ca95..a9667588cf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterItem.kt @@ -40,4 +40,13 @@ class ChapterItem(chapter: Chapter, val manga: Manga) : ) { holder.bind(this, manga) } + + override fun unbindViewHolder( + adapter: FlexibleAdapter>?, + holder: ChapterHolder?, + position: Int + ) { + super.unbindViewHolder(adapter, holder, position) + (adapter as MangaDetailsAdapter).controller.dismissPopup(position) + } }