Skip to content

Commit

Permalink
AND-5647 fixed crash on NFC dialog show
Browse files Browse the repository at this point in the history
  • Loading branch information
kozarezvlad committed Apr 8, 2024
1 parent f1f2606 commit cd282c3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.tangem.sdk

import android.app.Activity
import android.os.Build
import androidx.core.app.ComponentActivity
import com.tangem.Log
import com.tangem.Message
import com.tangem.SessionViewDelegate
Expand All @@ -27,7 +28,7 @@ import com.tangem.sdk.ui.NfcSessionDialog
*/
class DefaultSessionViewDelegate(
private val nfcManager: NfcManager,
private val activity: Activity,
private val activity: ComponentActivity,
) : SessionViewDelegate {

var sdkConfig: Config = Config()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.tangem.sdk.ui

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.provider.Settings
import androidx.appcompat.app.AlertDialog
import androidx.core.app.ComponentActivity
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.tangem.sdk.R
import com.tangem.sdk.extensions.sdkThemeContext
Expand All @@ -13,15 +15,17 @@ class NfcEnableDialog {

private var dialog: AlertDialog? = null

fun show(activity: Activity) {
fun show(activity: ComponentActivity) {
val builder = MaterialAlertDialogBuilder(activity.sdkThemeContext())
builder.setCancelable(false)
.setIcon(R.drawable.ic_action_nfc_gray)
.setTitle(R.string.dialog_nfc_enable_title)
.setMessage(R.string.dialog_nfc_enable_text)
.setPositiveButton(R.string.common_ok) { _, _ ->
try {
activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS))
if ((activity as? LifecycleOwner)?.lifecycle?.currentState == Lifecycle.State.STARTED) {
activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS))
}
} catch (ex: ActivityNotFoundException) {
print(ex.toString())
}
Expand Down

0 comments on commit cd282c3

Please # to comment.