Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND-8958 fix double dialog showing #418

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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)
Expand Down Expand Up @@ -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
}
}
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
Loading