From 7b8ee9d1f04a01c179155c8d823739550dec110c Mon Sep 17 00:00:00 2001 From: Vlad Kozarez Date: Mon, 11 Nov 2024 17:12:36 +0300 Subject: [PATCH] AND-8958 fix double dialog showing (use onDismiss callback) --- .../tangem/sdk/DefaultSessionViewDelegate.kt | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt b/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt index c56faee7..50f65184 100644 --- a/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt +++ b/tangem-sdk-android/src/main/java/com/tangem/sdk/DefaultSessionViewDelegate.kt @@ -185,21 +185,36 @@ class DefaultSessionViewDelegate( Log.view { "createAndShowState" } // Under the hood dialog dismiss could work async and new dialog could be created // before old one is dismissed, that leads to 2 dialogs on screen. - // Trying to use delay after dismiss previous dialog to avoid this + // Create new one in onDismiss callback postUI { - readingDialog?.dismissInternal() - } - postUI(DIALOG_CREATION_DELAY) { - with(createReadingDialog(activity, iconScanRes)) { - Log.view { "createReadingDialog readingDialog $this" } - showHowTo(enableHowTo) - setInitialMessage(message) - setScanImage(sdkConfig.scanTagImage) - show(state) + if (readingDialog != null) { + readingDialog?.setOnDismissListener { + Log.view { "old readingDialog onDismiss callback" } + createAndConfigureDialog(state, enableHowTo, message, iconScanRes) + } + readingDialog?.dismissInternal() + } else { + Log.view { "createAndConfigDialog" } + createAndConfigureDialog(state, enableHowTo, message, iconScanRes) } } } + private fun createAndConfigureDialog( + state: SessionViewDelegateState, + enableHowTo: Boolean, + message: ViewDelegateMessage? = null, + iconScanRes: Int? = null, + ) { + with(createReadingDialog(activity, iconScanRes)) { + Log.view { "createReadingDialog readingDialog $this" } + showHowTo(enableHowTo) + setInitialMessage(message) + setScanImage(sdkConfig.scanTagImage) + show(state) + } + } + private fun createReadingDialog(activity: Activity, iconScanRes: Int? = null): NfcSessionDialog { Log.view { "createReadingDialog" } return NfcSessionDialog( @@ -231,7 +246,6 @@ class DefaultSessionViewDelegate( } companion object { - private const val DIALOG_CREATION_DELAY = 200L private const val DIALOG_NFC_DELAY = 800L } }