Skip to content

Commit

Permalink
AND-8958 fix scan dialog (4th try)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozarezvlad committed Nov 15, 2024
1 parent afc6d13 commit f6fc9d5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class SecurityDelay : BaseDelegateAction() {
}
}

withMainContext { delegate.onSessionStopped(null) }
withMainContext { delegate.onSessionStopped(null) {} }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

/**
Expand Down

0 comments on commit f6fc9d5

Please sign in to comment.