Dismiss popup menu for chapters when scrolled off screen
This commit is contained in:
parent
69214984e4
commit
a5db1ff417
2 changed files with 19 additions and 0 deletions
|
@ -178,6 +178,7 @@ class MangaDetailsController : BaseController,
|
|||
private var textAnim: ViewPropertyAnimator? = null
|
||||
private var scrollAnim: ViewPropertyAnimator? = null
|
||||
var isTablet = false
|
||||
var chapterPopupMenu: Pair<Int, PopupMenu>? = 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
|
||||
|
|
|
@ -40,4 +40,13 @@ class ChapterItem(chapter: Chapter, val manga: Manga) :
|
|||
) {
|
||||
holder.bind(this, manga)
|
||||
}
|
||||
|
||||
override fun unbindViewHolder(
|
||||
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?,
|
||||
holder: ChapterHolder?,
|
||||
position: Int
|
||||
) {
|
||||
super.unbindViewHolder(adapter, holder, position)
|
||||
(adapter as MangaDetailsAdapter).controller.dismissPopup(position)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue