mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 12:27:39 +00:00
Fixed menu inflating unnecessarily on every click
This commit is contained in:
parent
dd9129017f
commit
f8bea66313
@ -470,18 +470,19 @@ interface OnPopupMenuItemClickListener {
|
|||||||
|
|
||||||
@BindingAdapter("popupMenu", "popupMenuOnClickListener", requireAll = false)
|
@BindingAdapter("popupMenu", "popupMenuOnClickListener", requireAll = false)
|
||||||
fun View.setPopupMenu(popupMenu: Int, listener: OnPopupMenuItemClickListener) {
|
fun View.setPopupMenu(popupMenu: Int, listener: OnPopupMenuItemClickListener) {
|
||||||
tag = tag as? PopupMenu ?: let {
|
val menu = tag as? PopupMenu ?: let {
|
||||||
val themeWrapper = ContextThemeWrapper(context, R.style.Foundation_PopupMenu)
|
val themeWrapper = ContextThemeWrapper(context, R.style.Foundation_PopupMenu)
|
||||||
PopupMenu(themeWrapper, this)
|
PopupMenu(themeWrapper, this)
|
||||||
}
|
}
|
||||||
setOnClickListener {
|
tag = menu.apply {
|
||||||
(tag as PopupMenu).apply {
|
this.menu.clear()
|
||||||
menuInflater.inflate(popupMenu, menu)
|
menuInflater.inflate(popupMenu, this.menu)
|
||||||
setOnMenuItemClickListener {
|
setOnMenuItemClickListener {
|
||||||
listener.onMenuItemClick(it.itemId)
|
listener.onMenuItemClick(it.itemId)
|
||||||
true
|
true
|
||||||
}
|
|
||||||
show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setOnClickListener {
|
||||||
|
(tag as PopupMenu).show()
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user