From 1fa7d5180c70475bf540437324c4ac4447170706 Mon Sep 17 00:00:00 2001 From: Mama1emon Date: Thu, 27 Jun 2024 17:09:19 +0800 Subject: [PATCH] AND-7444 [Floating] Infinite bottom sheet after scanning card --- .../tangem/sdk/DefaultSessionViewDelegate.kt | 57 ++++++++++--------- .../java/com/tangem/sdk/ui/BaseSdkDialog.kt | 17 +++--- 2 files changed, 37 insertions(+), 37 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 db045b0e..f68b8b6e 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 @@ -106,8 +106,9 @@ class DefaultSessionViewDelegate( ) { Log.view { "showing pin request with type: $type" } postUI(msTime = 200) { - if (readingDialog == null) createReadingDialog(activity) - readingDialog?.show( + val dialog = readingDialog ?: createReadingDialog(activity) + + dialog.show( SessionViewDelegateState.PinRequested( type = type, isFirstAttempt = isFirstAttempt, @@ -121,8 +122,9 @@ class DefaultSessionViewDelegate( override fun requestUserCodeChange(type: UserCodeType, cardId: String?, callback: CompletionCallback) { Log.view { "showing pin change request with type: $type" } - if (readingDialog == null) createReadingDialog(activity) - readingDialog?.show(SessionViewDelegateState.PinChangeRequested(type, cardId, callback)) + val dialog = readingDialog ?: createReadingDialog(activity) + + dialog.show(SessionViewDelegateState.PinChangeRequested(type, cardId, callback)) } override fun dismiss() { @@ -168,40 +170,41 @@ class DefaultSessionViewDelegate( iconScanRes: Int? = null, ) { postUI { - if (readingDialog == null) { - createReadingDialog(activity, iconScanRes) - } else { - readingDialog?.dismissInternal() - createReadingDialog(activity, iconScanRes) + readingDialog?.let(NfcSessionDialog::dismissInternal) + + with(createReadingDialog(activity, iconScanRes)) { + showHowTo(enableHowTo) + setInitialMessage(message) + setScanImage(sdkConfig.scanTagImage) + show(state) } - readingDialog?.showHowTo(enableHowTo) - readingDialog?.setInitialMessage(message) - readingDialog?.setScanImage(sdkConfig.scanTagImage) - readingDialog?.show(state) } } - private fun createReadingDialog(activity: Activity, iconScanRes: Int? = null) { - val nfcLocationProvider = NfcAntennaLocationProvider(Build.DEVICE) - readingDialog = NfcSessionDialog( + private fun createReadingDialog(activity: Activity, iconScanRes: Int? = null): NfcSessionDialog { + return NfcSessionDialog( context = activity.sdkThemeContext(), nfcManager = nfcManager, - nfcLocationProvider = nfcLocationProvider, + nfcLocationProvider = NfcAntennaLocationProvider(Build.DEVICE), iconScanRes = iconScanRes, - ).apply { - setOwnerActivity(activity) - dismissWithAnimation = true - stoppedBySession = false - create() - setOnCancelListener { - if (!stoppedBySession) nfcManager.reader.stopSession(true) - readingDialog = null + ) + .apply { + setOwnerActivity(activity) + dismissWithAnimation = true + stoppedBySession = false + create() + setOnCancelListener { + if (!stoppedBySession) nfcManager.reader.stopSession(true) + readingDialog = null + } + } + .also { + readingDialog = it } - } } private fun formatCardId(cardId: String?): String? { - val cardId = cardId ?: return null + cardId ?: return null val formatter = CardIdFormatter(sdkConfig.cardIdDisplayFormat) return formatter.getFormattedCardId(cardId) 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 c55cf1f8..eb0bff95 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 @@ -8,7 +8,6 @@ import androidx.transition.TransitionManager import com.google.android.material.bottomsheet.BottomSheetDialog import com.tangem.Log import com.tangem.sdk.SessionViewDelegateState -import com.tangem.sdk.postUI import com.tangem.sdk.ui.widget.StateWidget import kotlinx.android.synthetic.main.bottom_sheet_layout.* import java.util.concurrent.atomic.AtomicBoolean @@ -53,16 +52,14 @@ open class BaseSdkDialog(context: Context) : BottomSheetDialog(context) { } override fun dismiss() { - postUI { - if (!isDismissedProgrammatically.get()) { - // call it only if dismiss() called by system and not from dismissInternal() - stateWidgets.forEach { it.onBottomSheetDismiss() } - isDismissedProgrammatically.set(false) - } - if (ownerActivity == null || ownerActivity?.isFinishing == true) return@postUI - - super.dismiss() + if (!isDismissedProgrammatically.get()) { + // call it only if dismiss() called by system and not from dismissInternal() + stateWidgets.forEach { it.onBottomSheetDismiss() } + isDismissedProgrammatically.set(false) } + if (ownerActivity == null || ownerActivity?.isFinishing == true) return + + super.dismiss() } /**