From f8bea663136ce2e87833b129b56d55723af0c8cb Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Sat, 1 Feb 2020 14:51:20 +0100 Subject: [PATCH] Fixed menu inflating unnecessarily on every click --- .../magisk/utils/DataBindingAdapters.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt index e0eb1f21a..08ff13827 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt +++ b/app/src/main/java/com/topjohnwu/magisk/utils/DataBindingAdapters.kt @@ -470,18 +470,19 @@ interface OnPopupMenuItemClickListener { @BindingAdapter("popupMenu", "popupMenuOnClickListener", requireAll = false) 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) PopupMenu(themeWrapper, this) } - setOnClickListener { - (tag as PopupMenu).apply { - menuInflater.inflate(popupMenu, menu) - setOnMenuItemClickListener { - listener.onMenuItemClick(it.itemId) - true - } - show() + tag = menu.apply { + this.menu.clear() + menuInflater.inflate(popupMenu, this.menu) + setOnMenuItemClickListener { + listener.onMenuItemClick(it.itemId) + true } } + setOnClickListener { + (tag as PopupMenu).show() + } } \ No newline at end of file