Updated on 2026-08-14
This commit is contained in:
parent
e10bb40e6d
commit
7cd04e47b0
4 changed files with 26 additions and 14 deletions
|
|
@ -14,7 +14,6 @@ import com.tangem.common.CompletionResult
|
|||
import com.tangem.tangem_sdk_new.extensions.hide
|
||||
import com.tangem.tangem_sdk_new.extensions.show
|
||||
import com.tangem.tangem_sdk_new.nfc.NfcReader
|
||||
import com.tangem.tangem_sdk_new.ui.NfcEnableDialog
|
||||
import com.tangem.tangem_sdk_new.ui.TouchCardAnimation
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
import kotlinx.android.synthetic.main.nfc_bottom_sheet.*
|
||||
|
|
@ -35,7 +34,6 @@ class DefaultSessionViewDelegate(private val reader: NfcReader) : SessionViewDel
|
|||
override fun onNfcSessionStarted(cardId: String?, message: Message?) {
|
||||
reader.readingCancelled = false
|
||||
postUI { showReadingDialog(activity, cardId, message) }
|
||||
if (!reader.nfcEnabled) NfcEnableDialog().show(activity)
|
||||
}
|
||||
|
||||
private fun showReadingDialog(activity: Activity, cardId: String?, message: Message?) {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.nfc.tech.IsoDep
|
|||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import com.tangem.Log
|
||||
import com.tangem.tangem_sdk_new.ui.NfcEnableDialog
|
||||
|
||||
/**
|
||||
* Helps use NFC, leveraging Android NFC functionality.
|
||||
|
|
@ -22,6 +23,7 @@ class NfcManager : NfcAdapter.ReaderCallback {
|
|||
val reader = NfcReader()
|
||||
private var activity: Activity? = null
|
||||
private var nfcAdapter: NfcAdapter? = null
|
||||
private var nfcEnableDialog: NfcEnableDialog? = null
|
||||
|
||||
fun setCurrentActivity(activity: Activity) {
|
||||
this.activity = activity
|
||||
|
|
@ -47,16 +49,21 @@ class NfcManager : NfcAdapter.ReaderCallback {
|
|||
fun onResume() {
|
||||
val filter = IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)
|
||||
activity?.registerReceiver(mBroadcastReceiver, filter)
|
||||
|
||||
if ((nfcAdapter == null || nfcAdapter?.isEnabled != true)) {
|
||||
reader.nfcEnabled = false
|
||||
} else {
|
||||
reader.nfcEnabled = true
|
||||
enableReaderMode()
|
||||
}
|
||||
handleNfcEnabled(nfcAdapter?.isEnabled == true)
|
||||
reader.manager = this
|
||||
}
|
||||
|
||||
private fun handleNfcEnabled(nfcEnabled: Boolean) {
|
||||
reader.nfcEnabled = nfcEnabled
|
||||
if (nfcEnabled) {
|
||||
enableReaderMode()
|
||||
nfcEnableDialog?.cancel()
|
||||
} else {
|
||||
nfcEnableDialog = NfcEnableDialog()
|
||||
activity?.let{ nfcEnableDialog?.show(it) }
|
||||
}
|
||||
}
|
||||
|
||||
fun onPause() {
|
||||
activity?.unregisterReceiver(mBroadcastReceiver)
|
||||
disableReaderMode()
|
||||
|
|
|
|||
|
|
@ -8,16 +8,22 @@ import com.tangem.tangem_sdk_new.R
|
|||
|
||||
class NfcEnableDialog {
|
||||
|
||||
private var dialog: AlertDialog? = null
|
||||
|
||||
fun show(activity: Activity) {
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
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.general_ok
|
||||
) { _, _ ->
|
||||
activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS))
|
||||
}
|
||||
builder.create().show()
|
||||
.setPositiveButton(R.string.general_ok)
|
||||
{ _, _ -> activity.startActivity(Intent(Settings.ACTION_NFC_SETTINGS)) }
|
||||
.setNegativeButton(R.string.dialog_cancel) { dialog, _ -> dialog.cancel() }
|
||||
dialog = builder.create()
|
||||
dialog?.show()
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
dialog?.cancel()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<resources>
|
||||
<string name="app_name">Tangem Sdk</string>
|
||||
<string name="general_ok">OK</string>
|
||||
<string name="dialog_cancel">Cancel</string>
|
||||
<string name="dialog_nfc_enable_title">Enable NFC?</string>
|
||||
<string name="dialog_nfc_enable_text">This app is useless when NFC is disabled. Reader mode depends on it. Hit OK to go to Settings, where you can enable NFC.</string>
|
||||
<string name="dialog_security_delay">Security delay</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue