Skip to content

Commit

Permalink
Merge pull request #420 from tangem/merge_5.18_dev
Browse files Browse the repository at this point in the history
Merge 5.18 dev
  • Loading branch information
kozarezvlad authored Nov 14, 2024
2 parents a07ade0 + ec5c194 commit 3d234c9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -182,18 +182,39 @@ 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.
// Create new one in onDismiss callback
postUI {
readingDialog?.let(NfcSessionDialog::dismissInternal)

with(createReadingDialog(activity, iconScanRes)) {
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(
Expand Down Expand Up @@ -223,4 +244,8 @@ class DefaultSessionViewDelegate(
val formatter = CardIdFormatter(sdkConfig.cardIdDisplayFormat)
return formatter.getFormattedCardId(cardId)
}

companion object {
private const val DIALOG_NFC_DELAY = 800L
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() }
Expand All @@ -67,6 +68,7 @@ open class BaseSdkDialog(context: Context) : BottomSheetDialog(context) {
* StateWidget.onBottomSheetDismiss() callback
*/
fun dismissInternal() {
Log.view { "dismissInternal" }
isDismissedProgrammatically.set(true)
dismiss()
}
Expand Down

0 comments on commit 3d234c9

Please sign in to comment.