Skip to content

Commit

Permalink
AND-7444 [Floating] Infinite bottom sheet after scanning card
Browse files Browse the repository at this point in the history
  • Loading branch information
Mama1emon committed Jun 28, 2024
1 parent fa5028a commit 1fa7d51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -121,8 +122,9 @@ class DefaultSessionViewDelegate(

override fun requestUserCodeChange(type: UserCodeType, cardId: String?, callback: CompletionCallback<String>) {
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() {
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

/**
Expand Down

0 comments on commit 1fa7d51

Please # to comment.