Skip to content
New issue

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

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

Already on GitHub? # to your account

AND-5647 fixed crash on NFC dialog show #366

Merged
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 @@ -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
Loading