Dismiss overflow popup on click outside, avoid reopening on overflow button click

This commit is contained in:
Daniele Verducci 2025-01-08 07:46:49 +01:00
parent e1388f9bad
commit 524a121149

View File

@ -53,6 +53,7 @@ class MainActivity : AppCompatActivity() {
handler.postDelayed(updateListRunnable, 1000*60) handler.postDelayed(updateListRunnable, 1000*60)
} }
var logbookRepo: LogbookRepository? = null var logbookRepo: LogbookRepository? = null
var showingOverflowPopupWindow = false
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -466,6 +467,9 @@ class MainActivity : AppCompatActivity() {
} }
private fun showOverflowPopupWindow(anchor: View) { private fun showOverflowPopupWindow(anchor: View) {
if (showingOverflowPopupWindow)
return
PopupWindow(anchor.context).apply { PopupWindow(anchor.context).apply {
isOutsideTouchable = true isOutsideTouchable = true
val inflater = LayoutInflater.from(anchor.context) val inflater = LayoutInflater.from(anchor.context)
@ -487,7 +491,13 @@ class MainActivity : AppCompatActivity() {
dismiss() dismiss()
}) })
}.also { popupWindow -> }.also { popupWindow ->
popupWindow.setOnDismissListener({
Handler(mainLooper).postDelayed({
showingOverflowPopupWindow = false
}, 500)
})
popupWindow.showAsDropDown(anchor) popupWindow.showAsDropDown(anchor)
showingOverflowPopupWindow = true
} }
} }
} }