From f89246e728186086b55e0a1ecf9cdcbe14eae8e3 Mon Sep 17 00:00:00 2001 From: Vlad Kozarez Date: Mon, 11 Nov 2024 16:42:06 +0300 Subject: [PATCH] AND-8958 fix double dialog showing --- .../tangem/sdk/DefaultSessionViewDelegate.kt | 19 +++++++++++++++---- .../java/com/tangem/sdk/ui/BaseSdkDialog.kt | 2 ++ 2 files changed, 17 insertions(+), 4 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 8d37f9a0..c56faee7 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 @@ -47,7 +47,7 @@ class DefaultSessionViewDelegate( iconScanRes: Int?, productType: ProductType, ) { - Log.view { "session started" } + Log.view { "onSessionStarted" } createAndShowState( state = SessionViewDelegateState.Ready(formatCardId(cardId), productType), enableHowTo = enableHowTo, @@ -60,7 +60,7 @@ class DefaultSessionViewDelegate( private fun checkNfcEnabled() { Log.view { "checkNfcEnabled" } // workaround to delay checking isNfcEnabled to let nfcManager become enabled state after enableReaderMode - postUI(msTime = 700) { + postUI(msTime = DIALOG_NFC_DELAY) { Log.view { "checkNfcEnabled isNfcEnabled=${nfcManager.isNfcEnabled}" } if (!nfcManager.isNfcEnabled) { nfcEnableDialog?.cancel() @@ -182,10 +182,16 @@ class DefaultSessionViewDelegate( message: ViewDelegateMessage? = null, iconScanRes: Int? = null, ) { + 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 postUI { - readingDialog?.let(NfcSessionDialog::dismissInternal) - + readingDialog?.dismissInternal() + } + postUI(DIALOG_CREATION_DELAY) { with(createReadingDialog(activity, iconScanRes)) { + Log.view { "createReadingDialog readingDialog $this" } showHowTo(enableHowTo) setInitialMessage(message) setScanImage(sdkConfig.scanTagImage) @@ -223,4 +229,9 @@ class DefaultSessionViewDelegate( val formatter = CardIdFormatter(sdkConfig.cardIdDisplayFormat) return formatter.getFormattedCardId(cardId) } + + companion object { + private const val DIALOG_CREATION_DELAY = 200L + private const val DIALOG_NFC_DELAY = 800L + } } diff --git a/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/BaseSdkDialog.kt b/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/BaseSdkDialog.kt index eb0bff95..93731f77 100644 --- a/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/BaseSdkDialog.kt +++ b/tangem-sdk-android/src/main/java/com/tangem/sdk/ui/BaseSdkDialog.kt @@ -52,6 +52,7 @@ open class BaseSdkDialog(context: Context) : BottomSheetDialog(context) { } override fun dismiss() { + Log.view { "dismiss" } if (!isDismissedProgrammatically.get()) { // call it only if dismiss() called by system and not from dismissInternal() stateWidgets.forEach { it.onBottomSheetDismiss() } @@ -67,6 +68,7 @@ open class BaseSdkDialog(context: Context) : BottomSheetDialog(context) { * StateWidget.onBottomSheetDismiss() callback */ fun dismissInternal() { + Log.view { "dismissInternal" } isDismissedProgrammatically.set(true) dismiss() }