From 25a35099886beb46becb687659f19972cb3ab50d Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Sat, 13 Aug 2022 14:39:01 +0200 Subject: [PATCH] Reimplementing the multiple popups handling in the new popup solution. --- .../activities/common/dialogs/NumberPopup.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPopup.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPopup.kt index 20592a496..28ecc50ed 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPopup.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberPopup.kt @@ -73,6 +73,7 @@ class NumberPopup( } fun show() { + clearCurrentDialog() dialog = Dialog(context, android.R.style.Theme_NoTitleBar) dialog.setContentView(view.root) dialog.window?.apply { @@ -84,6 +85,7 @@ class NumberPopup( } dialog.setOnDismissListener { onDismiss() + currentDialog = null } view.value.setOnKeyListener { _, keyCode, event -> @@ -103,6 +105,7 @@ class NumberPopup( view.value.requestFocusWithKeyboard() dialog.setCanceledOnTouchOutside(true) dialog.dimBehind() + currentDialog = dialog dialog.show() } @@ -112,4 +115,14 @@ class NumberPopup( onToggle(value, notes) dialog.dismiss() } + + companion object { + // Used to make sure that 2 popups aren't shown on top of each other + // If dialog that's already shown is detected, it's dismissed before the next one is opened. + private var currentDialog: Dialog? = null + fun clearCurrentDialog() { + currentDialog?.dismiss() + currentDialog = null + } + } }