diff --git a/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/tasksLogger/CommandsTesterFragment.kt b/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/tasksLogger/CommandsTesterFragment.kt index 483529ea..431acfb6 100644 --- a/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/tasksLogger/CommandsTesterFragment.kt +++ b/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/tasksLogger/CommandsTesterFragment.kt @@ -189,7 +189,7 @@ class SdkTaskSpinnerFragment : BaseFragment() { override fun onTagLost(productType: ProductType) {} override fun onTagConnected() {} override fun onWrongCard(wrongValueType: WrongValueType) {} - override fun onSessionStopped(message: Message?) {} + override fun onSessionStopped(message: Message?, onDialogHidden: () -> Unit) {} override fun onError(error: TangemError) {} override fun requestUserCode( type: UserCodeType, diff --git a/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/viewDelegate/ViewDelegateAction.kt b/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/viewDelegate/ViewDelegateAction.kt index c3e11fbe..6bd63c3b 100644 --- a/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/viewDelegate/ViewDelegateAction.kt +++ b/tangem-sdk-android-demo/src/main/java/com/tangem/demo/ui/viewDelegate/ViewDelegateAction.kt @@ -149,7 +149,7 @@ class SecurityDelay : BaseDelegateAction() { } } - withMainContext { delegate.onSessionStopped(null) } + withMainContext { delegate.onSessionStopped(null) {} } } } 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 f466d464..bfef8182 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 @@ -73,10 +73,13 @@ class DefaultSessionViewDelegate( } } - override fun onSessionStopped(message: Message?) { + override fun onSessionStopped(message: Message?, onDialogHidden: () -> Unit) { Log.view { "session stopped" } stoppedBySession = true - readingDialog?.show(SessionViewDelegateState.Success(message), ::onDialogShown) + readingDialog?.show(SessionViewDelegateState.Success(message)) { + onDialogShown() + onDialogHidden() + } } override fun onSecurityDelay(ms: Int, totalDurationSeconds: Int, productType: ProductType) { @@ -191,19 +194,12 @@ class DefaultSessionViewDelegate( 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. - // Create new one in onDismiss callback postUI { - if (readingDialog != null && readingDialog?.isShowing == true) { - readingDialog?.setOnDismissListener { - Log.view { "old readingDialog onDismiss callback" } - createAndConfigureDialog(state, enableHowTo, message, iconScanRes) - } - readingDialog?.dismissInternal() - } else { + if (readingDialog == null) { Log.view { "createAndConfigDialog" } createAndConfigureDialog(state, enableHowTo, message, iconScanRes) + } else { + readingDialog?.show(state, ::onDialogShown) } } } diff --git a/tangem-sdk-core/src/main/java/com/tangem/SessionViewDelegate.kt b/tangem-sdk-core/src/main/java/com/tangem/SessionViewDelegate.kt index 44fd3135..1742ebe0 100644 --- a/tangem-sdk-core/src/main/java/com/tangem/SessionViewDelegate.kt +++ b/tangem-sdk-core/src/main/java/com/tangem/SessionViewDelegate.kt @@ -55,7 +55,7 @@ interface SessionViewDelegate { /** * It is called when NFC session was completed and a user can take the card away from the Android device. */ - fun onSessionStopped(message: Message? = null) + fun onSessionStopped(message: Message? = null, onDialogHidden: () -> Unit) /** * It is called when some error occur during NFC session. diff --git a/tangem-sdk-core/src/main/java/com/tangem/common/core/CardSession.kt b/tangem-sdk-core/src/main/java/com/tangem/common/core/CardSession.kt index 5e2a5456..068b9a27 100644 --- a/tangem-sdk-core/src/main/java/com/tangem/common/core/CardSession.kt +++ b/tangem-sdk-core/src/main/java/com/tangem/common/core/CardSession.kt @@ -359,8 +359,9 @@ class CardSession( * @param message If null, the default message will be shown. */ private fun stop(message: Message? = null) { - viewDelegate.onSessionStopped(message) - stopSessionIfActive() + viewDelegate.onSessionStopped(message) { + stopSessionIfActive() + } } /**