From 524a121149c65e7deeaf5a238f2f5520c3327a68 Mon Sep 17 00:00:00 2001 From: Daniele Verducci Date: Wed, 8 Jan 2025 07:46:49 +0100 Subject: [PATCH] Dismiss overflow popup on click outside, avoid reopening on overflow button click --- .../it/danieleverducci/lunatracker/MainActivity.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt index 3cefd95..4a5a26b 100644 --- a/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt +++ b/app/src/main/java/it/danieleverducci/lunatracker/MainActivity.kt @@ -53,6 +53,7 @@ class MainActivity : AppCompatActivity() { handler.postDelayed(updateListRunnable, 1000*60) } var logbookRepo: LogbookRepository? = null + var showingOverflowPopupWindow = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -466,6 +467,9 @@ class MainActivity : AppCompatActivity() { } private fun showOverflowPopupWindow(anchor: View) { + if (showingOverflowPopupWindow) + return + PopupWindow(anchor.context).apply { isOutsideTouchable = true val inflater = LayoutInflater.from(anchor.context) @@ -487,7 +491,13 @@ class MainActivity : AppCompatActivity() { dismiss() }) }.also { popupWindow -> + popupWindow.setOnDismissListener({ + Handler(mainLooper).postDelayed({ + showingOverflowPopupWindow = false + }, 500) + }) popupWindow.showAsDropDown(anchor) + showingOverflowPopupWindow = true } } }