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 textAnim: ViewPropertyAnimator? = null
|
||||||
private var scrollAnim: ViewPropertyAnimator? = null
|
private var scrollAnim: ViewPropertyAnimator? = null
|
||||||
var isTablet = false
|
var isTablet = false
|
||||||
|
var chapterPopupMenu: Pair<Int, PopupMenu>? = null
|
||||||
|
|
||||||
// Tablet Layout
|
// Tablet Layout
|
||||||
var tabletRecycler: RecyclerView? = null
|
var tabletRecycler: RecyclerView? = null
|
||||||
|
@ -647,6 +648,7 @@ class MangaDetailsController : BaseController,
|
||||||
val item = (adapter.getItem(position) as? ChapterItem) ?: return
|
val item = (adapter.getItem(position) as? ChapterItem) ?: return
|
||||||
val itemView = getHolder(item)?.itemView ?: return
|
val itemView = getHolder(item)?.itemView ?: return
|
||||||
val popup = PopupMenu(itemView.context, itemView)
|
val popup = PopupMenu(itemView.context, itemView)
|
||||||
|
chapterPopupMenu = position to popup
|
||||||
|
|
||||||
// Inflate our menu resource into the PopupMenu's Menu
|
// Inflate our menu resource into the PopupMenu's Menu
|
||||||
popup.menuInflater.inflate(R.menu.chapter_single, popup.menu)
|
popup.menuInflater.inflate(R.menu.chapter_single, popup.menu)
|
||||||
|
@ -656,6 +658,7 @@ class MangaDetailsController : BaseController,
|
||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.action_mark_previous_as_read -> markPreviousAsRead(item)
|
R.id.action_mark_previous_as_read -> markPreviousAsRead(item)
|
||||||
}
|
}
|
||||||
|
chapterPopupMenu = null
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,6 +666,13 @@ class MangaDetailsController : BaseController,
|
||||||
popup.show()
|
popup.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dismissPopup(position: Int) {
|
||||||
|
if (chapterPopupMenu != null && chapterPopupMenu?.first == position) {
|
||||||
|
chapterPopupMenu?.second?.dismiss()
|
||||||
|
chapterPopupMenu = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun markPreviousAsRead(chapter: ChapterItem) {
|
private fun markPreviousAsRead(chapter: ChapterItem) {
|
||||||
val adapter = adapter ?: return
|
val adapter = adapter ?: return
|
||||||
val chapters = if (presenter.sortDescending()) adapter.items.reversed() else adapter.items
|
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)
|
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