Updated on 2026-08-14
This commit is contained in:
commit
2402efda34
317 changed files with 2877 additions and 2683 deletions
|
|
@ -1,192 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcDeviceAntennaLocation
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_android.android.reader.NfcReader
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.card_android.data.asBundle
|
||||
import com.tangem.card_common.reader.CardProtocol
|
||||
import com.tangem.card_common.tasks.CreateNewWalletTask
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_create_new_wallet.*
|
||||
import kotlinx.android.synthetic.main.layout_progress_horizontal.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
|
||||
class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
|
||||
companion object {
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, CreateNewWalletActivity::class.java)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private lateinit var nfcDeviceAntenna: NfcDeviceAntennaLocation
|
||||
|
||||
private var createNewWalletTask: CreateNewWalletTask? = null
|
||||
private var lastReadSuccess = true
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_create_new_wallet)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
// init NFC Antenna
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(this, ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna.init()
|
||||
|
||||
tvCardId.text = ctx.card!!.cidDescription
|
||||
progressBar.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
// get IsoDep handle and run cardReader thread
|
||||
val isoDep = IsoDep.get(tag)
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
|
||||
if (sUID == ctx.card.uid) {
|
||||
if (lastReadSuccess)
|
||||
isoDep.timeout = ctx.card.pauseBeforePIN2 + 5000
|
||||
else
|
||||
isoDep.timeout = ctx.card.pauseBeforePIN2 + 65000
|
||||
|
||||
createNewWalletTask = CreateNewWalletTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this)
|
||||
createNewWalletTask?.start()
|
||||
} else
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
createNewWalletTask?.cancel(true)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
rlProgressBar?.post { rlProgressBar.visibility = View.VISIBLE }
|
||||
|
||||
progressBar?.post {
|
||||
progressBar?.visibility = View.VISIBLE
|
||||
progressBar?.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadFinish(cardProtocol: CardProtocol?) {
|
||||
createNewWalletTask = null
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
rlProgressBar.post { rlProgressBar.visibility = View.GONE }
|
||||
|
||||
progressBar?.post {
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.GREEN)
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
lastReadSuccess = false
|
||||
if (cardProtocol.error is CardProtocol.TangemException_InvalidPIN) {
|
||||
progressBar?.post {
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, getString(R.string.nfc_error_cannot_create_wallet))
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card!!.asBundle)
|
||||
setResult(Constant.RESULT_INVALID_PIN, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
} else {
|
||||
progressBar?.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed) {
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
}
|
||||
} else
|
||||
Toast.makeText(this, R.string.general_notification_scan_again, Toast.LENGTH_SHORT).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rlProgressBar.postDelayed({ rlProgressBar?.visibility = View.GONE }, 500)
|
||||
|
||||
progressBar?.postDelayed({
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadProgress(protocol: CardProtocol, progress: Int) {
|
||||
progressBar?.post { progressBar?.progress = progress }
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
createNewWalletTask = null
|
||||
|
||||
progressBar?.postDelayed({
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_android.android.reader.NfcReader
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.card_android.data.asBundle
|
||||
import com.tangem.card_android.data.loadFromBundle
|
||||
import com.tangem.card_common.data.TangemCard
|
||||
import com.tangem.card_common.reader.CardProtocol
|
||||
import com.tangem.card_common.tasks.VerifyCardTask
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.di.ToastHelper
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_empty_wallet.*
|
||||
import kotlinx.android.synthetic.main.layout_tangem_card.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = EmptyWalletActivity::class.java.simpleName
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, EmptyWalletActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
@Inject
|
||||
internal lateinit var toastHelper: ToastHelper
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var lastReadSuccess = true
|
||||
private var verifyCardTask: VerifyCardTask? = null
|
||||
private var requestPIN2Count = 0
|
||||
|
||||
private var cardProtocol: CardProtocol? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_empty_wallet)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
App.toastHelperComponent.inject(this)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
tvIssuer.text = ctx.card!!.issuerDescription
|
||||
|
||||
if (ctx.card!!.tokenSymbol.length > 1) {
|
||||
@Suppress("DEPRECATION") val html = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
Html.fromHtml(ctx.blockchainName, Html.FROM_HTML_MODE_LEGACY)
|
||||
else
|
||||
Html.fromHtml(ctx.blockchainName)
|
||||
tvBlockchain.text = html
|
||||
} else
|
||||
tvBlockchain.text = ctx.blockchainName
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
ivTangemCard.setImageBitmap(App.localStorage.getCardArtworkBitmap(ctx.card))
|
||||
|
||||
// set listeners
|
||||
btnNewWallet.setOnClickListener {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2)
|
||||
}
|
||||
|
||||
btnDetails.setOnClickListener {
|
||||
if (cardProtocol != null)
|
||||
navigator.showVerifyCard(this, ctx)
|
||||
else
|
||||
toastHelper.showSingleToast(this, getString(R.string.general_notification_scan_again_to_verify))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (requestCode == Constant.REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, "updateAndViewCard")
|
||||
data.putExtra("updateDelay", 0)
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
finish()
|
||||
} else {
|
||||
if (data != null && data.extras!!.containsKey(EXTRA_TANGEM_CARD_UID) && data.extras!!.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getStringExtra(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundleExtra(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
val intent = Intent(baseContext, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2)
|
||||
return
|
||||
}
|
||||
}
|
||||
setResult(resultCode, data)
|
||||
finish()
|
||||
} else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
navigator.showCreateNewWallet(this, ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
val isoDep = IsoDep.get(tag)
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (ctx.card.uid != sUID) {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
return
|
||||
}
|
||||
|
||||
if (lastReadSuccess)
|
||||
isoDep.timeout = 1000
|
||||
else
|
||||
isoDep.timeout = 65000
|
||||
|
||||
verifyCardTask = VerifyCardTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, App.firmwaresStorage, this)
|
||||
verifyCardTask?.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
rlProgressBar?.post { rlProgressBar.visibility = View.VISIBLE }
|
||||
|
||||
progressBar?.post {
|
||||
progressBar?.visibility = View.VISIBLE
|
||||
progressBar?.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadFinish(cardProtocol: CardProtocol?) {
|
||||
verifyCardTask = null
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
rlProgressBar?.post { rlProgressBar.visibility = View.GONE }
|
||||
|
||||
progressBar?.post {
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.GREEN)
|
||||
this.cardProtocol = cardProtocol
|
||||
}
|
||||
} else {
|
||||
// remove last UIDs because of error and no card read
|
||||
progressBar?.post {
|
||||
lastReadSuccess = false
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed)
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
} else
|
||||
Toast.makeText(this@EmptyWalletActivity, R.string.general_notification_scan_again, Toast.LENGTH_LONG).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rlProgressBar?.postDelayed({
|
||||
try {
|
||||
rlProgressBar?.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadProgress(protocol: CardProtocol, progress: Int) {
|
||||
progressBar?.post { progressBar!!.progress = progress }
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
verifyCardTask = null
|
||||
|
||||
rlProgressBar?.postDelayed({
|
||||
try {
|
||||
rlProgressBar?.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.tangem.ui.navigation.NavigationResult
|
||||
|
||||
class GlobalViewModel : ViewModel() {
|
||||
var navigationResult: NavigationResult? = null
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.di.ToastHelper
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.ui.fragment.LoadedWalletFragment
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoadedWalletActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var navigator: Navigator
|
||||
@Inject
|
||||
internal lateinit var toastHelper: ToastHelper
|
||||
|
||||
companion object {
|
||||
fun callingIntent(context: Context, lastTag: Tag, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, LoadedWalletActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_LAST_DISCOVERED_TAG, lastTag)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_loaded_wallet)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
App.toastHelperComponent.inject(this)
|
||||
|
||||
if (intent.extras!!.containsKey(NfcAdapter.EXTRA_TAG)) {
|
||||
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) {
|
||||
val fragment = supportFragmentManager.findFragmentById(R.id.loaded_wallet_fragment) as LoadedWalletFragment
|
||||
fragment.onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_logo.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class LogoActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
fun callingIntent(context: Context, autoHide: Boolean): Intent {
|
||||
val intent = Intent(context, LogoActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_AUTO_HIDE, autoHide)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
|
||||
private val hideRunnable = Runnable { this.hide() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_logo)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
|
||||
clLogoContainer.setOnClickListener { hide() }
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
// set beta version name
|
||||
if (BuildConfig.DEBUG)
|
||||
tvAppVersion.text = String.format(getString(R.string.splash_version_name_debug), BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
|
||||
else
|
||||
tvAppVersion.text = String.format(getString(R.string.splash_version_name_release), BuildConfig.VERSION_NAME)
|
||||
|
||||
// set flavor app name
|
||||
when (BuildConfig.FLAVOR) {
|
||||
Constant.FLAVOR_TANGEM_CARDANO -> {
|
||||
tvExtension.visibility = View.VISIBLE
|
||||
tvExtension.text = getString(R.string.splash_cardano)
|
||||
}
|
||||
else -> {
|
||||
tvExtension.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(Constant.EXTRA_AUTO_HIDE, true))
|
||||
ivLogo.postDelayed(hideRunnable, Constant.MILLIS_AUTO_HIDE.toLong())
|
||||
}
|
||||
|
||||
private fun hide() {
|
||||
when (BuildConfig.FLAVOR) {
|
||||
Constant.FLAVOR_TANGEM_CARDANO -> {
|
||||
navigator.showPrepareTransaction(this, TangemContext())
|
||||
}
|
||||
else -> {
|
||||
navigator.showMain(this)
|
||||
}
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -13,31 +13,29 @@ import android.os.Bundle
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import com.scottyab.rootbeer.RootBeer
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.di.ToastHelper
|
||||
import com.tangem.tangem_sdk.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.tangem_sdk.android.reader.NfcManager
|
||||
import com.tangem.ui.dialog.RootFoundDialog
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = MainActivity::class.java.simpleName
|
||||
fun callingIntent(context: Context) = Intent(context, MainActivity::class.java)
|
||||
}
|
||||
|
||||
lateinit var navController: NavController
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
@Inject
|
||||
internal lateinit var toastHelper: ToastHelper
|
||||
lateinit var viewModel: GlobalViewModel
|
||||
lateinit var nfcManager: NfcManager
|
||||
|
||||
// private var onNfcReaderCallback: NfcAdapter.ReaderCallback? = null
|
||||
|
||||
|
|
@ -46,9 +44,7 @@ class MainActivity : AppCompatActivity() {
|
|||
if (intent != null && (NfcAdapter.ACTION_TECH_DISCOVERED == intent.action || NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action)) {
|
||||
val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) {
|
||||
val activeFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
|
||||
?.childFragmentManager?.primaryNavigationFragment
|
||||
(activeFragment as? NfcAdapter.ReaderCallback)?.onTagDiscovered(tag)
|
||||
onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -57,15 +53,17 @@ class MainActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
|
||||
viewModel = ViewModelProviders.of(this).get(GlobalViewModel::class.java)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
App.toastHelperComponent.inject(this)
|
||||
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
|
||||
verifyPermissions()
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
// // NFC
|
||||
// val intent = intent
|
||||
// if (intent != null && (NfcAdapter.ACTION_TECH_DISCOVERED == intent.action || NfcAdapter.ACTION_NDEF_DISCOVERED == intent.action)) {
|
||||
|
|
@ -88,4 +86,14 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
val activeFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment)
|
||||
?.childFragmentManager?.primaryNavigationFragment
|
||||
if (activeFragment is NfcAdapter.ReaderCallback) {
|
||||
activeFragment.onTagDiscovered(tag)
|
||||
} else {
|
||||
nfcManager.ignoreTag(tag)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,350 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Activity
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.fingerprint.FingerprintManager
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.data.PINStorage
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.card_android.data.loadFromBundle
|
||||
import com.tangem.card_common.data.TangemCard
|
||||
import com.tangem.data.fingerprint.FingerprintHelper
|
||||
import com.tangem.data.fingerprint.StartFingerprintReaderTask
|
||||
import com.tangem.util.LOG
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_pin_request.*
|
||||
import kotlinx.android.synthetic.main.layout_pin_buttons.*
|
||||
import java.io.IOException
|
||||
|
||||
class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, FingerprintHelper.FingerprintHelperListener {
|
||||
companion object {
|
||||
val TAG: String = PinRequestActivity::class.java.simpleName
|
||||
|
||||
fun callingIntent(context: Activity, mode: String): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun callingIntentRequestPin(context: Activity, mode: String, ctx: TangemContext, newPIN: String): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun callingIntentRequestPin2(context: Activity, mode: String, ctx: TangemContext, newPIN2: String): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun callingIntentRequestPin2(context: Activity, mode: String, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun callingIntentConfirmPin(context: Activity, mode: String, newPIN: String): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
return intent
|
||||
}
|
||||
|
||||
fun callingIntentConfirmPin2(context: Activity, mode: String, newPIN2: String): Intent {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, mode)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
lateinit var mode: Mode
|
||||
private var allowFingerprint = false
|
||||
var startFingerprintReaderTask: StartFingerprintReaderTask? = null
|
||||
private var fingerprintManager: FingerprintManager? = null
|
||||
private var fingerprintHelper: FingerprintHelper? = null
|
||||
|
||||
enum class Mode {
|
||||
RequestPIN, RequestPIN2, RequestNewPIN, RequestNewPIN2, ConfirmNewPIN, ConfirmNewPIN2
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pin_request)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
mode = Mode.valueOf(intent.getStringExtra(Constant.EXTRA_MODE))
|
||||
|
||||
if (mode == Mode.RequestNewPIN)
|
||||
if (PINStorage.haveEncryptedPIN()) {
|
||||
allowFingerprint = true
|
||||
tvPinPrompt.setText(R.string.pin_request_enter_new_pin_or_use_fingerprint_scanner)
|
||||
} else
|
||||
tvPinPrompt.setText(R.string.pin_request_enter_new_pin)
|
||||
else if (mode == Mode.ConfirmNewPIN)
|
||||
tvPinPrompt.setText(R.string.pin_request_confirm_new_pin)
|
||||
else if (mode == Mode.RequestPIN)
|
||||
if (PINStorage.haveEncryptedPIN()) {
|
||||
allowFingerprint = true
|
||||
tvPinPrompt.setText(R.string.pin_request_enter_pin_or_use_fingerprint_scanner)
|
||||
} else
|
||||
tvPinPrompt.setText(R.string.pin_request_enter_pin)
|
||||
else if (mode == Mode.RequestNewPIN2)
|
||||
if (PINStorage.haveEncryptedPIN2()) {
|
||||
allowFingerprint = true
|
||||
tvPinPrompt.setText(R.string.pin_request_prompt_new_pin_2_or_fingerprint)
|
||||
} else
|
||||
tvPinPrompt.setText(R.string.pin_request_new_pin_2)
|
||||
else if (mode == Mode.ConfirmNewPIN2)
|
||||
tvPinPrompt.setText(R.string.pin_request_confirm_new_pin_2)
|
||||
else if (mode == Mode.RequestPIN2) {
|
||||
val uid = intent.getStringExtra(EXTRA_TANGEM_CARD_UID)
|
||||
val card = TangemCard(uid)
|
||||
card.loadFromBundle(intent.getBundleExtra(EXTRA_TANGEM_CARD))
|
||||
|
||||
if (card.PIN2 == TangemCard.PIN2_Mode.DefaultPIN2 || card.PIN2 == TangemCard.PIN2_Mode.Unchecked) {
|
||||
// if we know PIN2 or not try default previously - use it
|
||||
PINStorage.setPIN2(PINStorage.getDefaultPIN2())
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
return
|
||||
}
|
||||
|
||||
if (PINStorage.haveEncryptedPIN2()) {
|
||||
allowFingerprint = true
|
||||
tvPinPrompt.setText(R.string.pin_request_enter_pin_2_or_use_fingerprint_scanner)
|
||||
} else
|
||||
tvPinPrompt.setText(R.string.pin_request_prompt_enter_pin_2)
|
||||
}
|
||||
|
||||
if (!allowFingerprint)
|
||||
tvPinPrompt.visibility = View.GONE
|
||||
else
|
||||
tvPinPrompt.visibility = View.VISIBLE
|
||||
|
||||
// set listeners
|
||||
btn0.setOnClickListener { buttonClick(btn0) }
|
||||
btn1.setOnClickListener { buttonClick(btn1) }
|
||||
btn2.setOnClickListener { buttonClick(btn2) }
|
||||
btn3.setOnClickListener { buttonClick(btn3) }
|
||||
btn4.setOnClickListener { buttonClick(btn4) }
|
||||
btn5.setOnClickListener { buttonClick(btn5) }
|
||||
btn6.setOnClickListener { buttonClick(btn6) }
|
||||
btn7.setOnClickListener { buttonClick(btn7) }
|
||||
btn8.setOnClickListener { buttonClick(btn8) }
|
||||
btn9.setOnClickListener { buttonClick(btn9) }
|
||||
btnBackspace.setOnClickListener {
|
||||
val s = tvPin!!.text.toString()
|
||||
if (s.isNotEmpty())
|
||||
tvPin!!.text = s.substring(0, s.length - 1)
|
||||
}
|
||||
btnContinue.setOnClickListener { doContinue() }
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
fingerprintHelper?.cancel()
|
||||
|
||||
if (startFingerprintReaderTask != null) {
|
||||
startFingerprintReaderTask!!.cancel(true)
|
||||
startFingerprintReaderTask = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
fingerprintHelper?.cancel()
|
||||
|
||||
if (startFingerprintReaderTask != null) {
|
||||
startFingerprintReaderTask!!.cancel(true)
|
||||
startFingerprintReaderTask = null
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (allowFingerprint)
|
||||
startFingerprintReader()
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
Log.w(javaClass.name, "Ignore discovered tag!")
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun authenticationFailed(error: String) {
|
||||
LOG.w(TAG, error)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
override fun authenticationSucceeded(result: FingerprintManager.AuthenticationResult) {
|
||||
LOG.i(TAG, "Authentication succeeded!")
|
||||
val cipher = result.cryptoObject.cipher
|
||||
|
||||
if (mode == Mode.RequestNewPIN || mode == Mode.ConfirmNewPIN) {
|
||||
val resultData = Intent()
|
||||
val pin = PINStorage.loadEncryptedPIN(cipher)
|
||||
resultData.putExtra(Constant.EXTRA_NEW_PIN, pin)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN, pin)
|
||||
setResult(Activity.RESULT_OK, resultData)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestNewPIN2 || mode == Mode.ConfirmNewPIN2) {
|
||||
val resultData = Intent()
|
||||
val pin = PINStorage.loadEncryptedPIN2(cipher)
|
||||
resultData.putExtra(Constant.EXTRA_NEW_PIN_2, pin)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN_2, pin)
|
||||
setResult(Activity.RESULT_OK, resultData)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestPIN) {
|
||||
PINStorage.loadEncryptedPIN(cipher)
|
||||
setResult(Activity.RESULT_OK)
|
||||
} else if (mode == Mode.RequestPIN2) {
|
||||
PINStorage.loadEncryptedPIN2(cipher)
|
||||
setResult(Activity.RESULT_OK)
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun buttonClick(button: Button) {
|
||||
tvPin.text = tvPin.text.toString() + button.text.toString()
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun testFingerPrintSettings(): Boolean {
|
||||
LOG.i(TAG, "Testing Fingerprint SettingsFragment")
|
||||
|
||||
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
fingerprintManager = getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
|
||||
|
||||
if (!keyguardManager.isKeyguardSecure) {
|
||||
LOG.i(TAG, "User hasn't enabled Lock Screen")
|
||||
return false
|
||||
}
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
|
||||
LOG.i(TAG, "User hasn't granted permission to use Fingerprint")
|
||||
return false
|
||||
}
|
||||
|
||||
if (!fingerprintManager!!.hasEnrolledFingerprints()) {
|
||||
LOG.i(TAG, "User hasn't registered any fingerprints")
|
||||
return false
|
||||
}
|
||||
|
||||
LOG.i(TAG, "Fingerprint authentication is set.\n")
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private fun startFingerprintReader() {
|
||||
if (!testFingerPrintSettings())
|
||||
return
|
||||
|
||||
if (!allowFingerprint)
|
||||
return
|
||||
|
||||
fingerprintHelper = FingerprintHelper(this@PinRequestActivity)
|
||||
startFingerprintReaderTask = StartFingerprintReaderTask(this, fingerprintManager, fingerprintHelper)
|
||||
startFingerprintReaderTask!!.execute(null as Void?)
|
||||
}
|
||||
|
||||
private fun doContinue() {
|
||||
if (startFingerprintReaderTask != null)
|
||||
return
|
||||
|
||||
// reset errors.
|
||||
tvPin!!.error = null
|
||||
|
||||
// store values at the time of the login attempt.
|
||||
val pin = tvPin!!.text.toString()
|
||||
|
||||
var cancel = false
|
||||
var focusView: View? = null
|
||||
|
||||
if (mode == Mode.ConfirmNewPIN) {
|
||||
if (pin != intent.getStringExtra(Constant.EXTRA_NEW_PIN)) {
|
||||
tvPin!!.error = getString(R.string.pin_request_error_pin_confirmation_failed)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
}
|
||||
} else if (mode == Mode.ConfirmNewPIN2) {
|
||||
if (pin != intent.getStringExtra(Constant.EXTRA_NEW_PIN_2)) {
|
||||
tvPin!!.error = getString(R.string.pin_request_error_pin_confirmation_failed)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
}
|
||||
} else {
|
||||
if (TextUtils.isEmpty(pin)) {
|
||||
tvPin!!.error = getString(R.string.error_empty_pin)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
}
|
||||
}
|
||||
|
||||
if (cancel)
|
||||
focusView!!.requestFocus()
|
||||
else {
|
||||
if (mode == Mode.RequestNewPIN || mode == Mode.ConfirmNewPIN) {
|
||||
val resultData = Intent()
|
||||
resultData.putExtra(Constant.EXTRA_NEW_PIN, pin)
|
||||
if (mode == Mode.ConfirmNewPIN)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN, pin)
|
||||
|
||||
setResult(Activity.RESULT_OK, resultData)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestNewPIN2 || mode == Mode.ConfirmNewPIN2) {
|
||||
val resultData = Intent()
|
||||
resultData.putExtra(Constant.EXTRA_NEW_PIN_2, pin)
|
||||
if (mode == Mode.ConfirmNewPIN2)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN_2, pin)
|
||||
|
||||
setResult(Activity.RESULT_OK, resultData)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestPIN) {
|
||||
PINStorage.setUserPIN(pin)
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestPIN2) {
|
||||
PINStorage.setPIN2(pin)
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,378 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Dialog
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.hardware.fingerprint.FingerprintManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyPermanentlyInvalidatedException
|
||||
import android.security.keystore.KeyProperties
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.data.PINStorage
|
||||
import com.tangem.data.fingerprint.ConfirmWithFingerprintTask
|
||||
import com.tangem.data.fingerprint.FingerprintHelper
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_save.*
|
||||
import kotlinx.android.synthetic.main.layout_pin_buttons.*
|
||||
import java.io.IOException
|
||||
import java.security.KeyStore
|
||||
import java.security.KeyStoreException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.security.cert.CertificateException
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.KeyGenerator
|
||||
import javax.crypto.NoSuchPaddingException
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
|
||||
class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelperListener {
|
||||
companion object {
|
||||
val TAG: String = PinSaveActivity::class.java.simpleName
|
||||
|
||||
fun callingIntent(context: Context, hasPin2: Boolean): Intent {
|
||||
val intent = Intent(context, PinSaveActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_PIN2, hasPin2)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
private var confirmWithFingerprintTask: ConfirmWithFingerprintTask? = null
|
||||
private var keyStore: KeyStore? = null
|
||||
private var cipher: Cipher? = null
|
||||
var fingerprintManager: FingerprintManager? = null
|
||||
var cryptoObject: FingerprintManager.CryptoObject? = null
|
||||
var fingerprintHelper: FingerprintHelper? = null
|
||||
private var usePIN2 = false
|
||||
private var onConfirmAction: OnConfirmAction? = null
|
||||
var dFingerPrintConfirmation: Dialog? = null
|
||||
|
||||
private enum class OnConfirmAction {
|
||||
Save, DeleteEncryptedAndSave, Delete
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pin_save)
|
||||
|
||||
usePIN2 = intent.getBooleanExtra(Constant.EXTRA_PIN2, false)
|
||||
|
||||
if (usePIN2)
|
||||
tvPinPrompt.text = getString(R.string.pin_save_title_enter_pin2_and_save)
|
||||
else
|
||||
tvPinPrompt.text = getString(R.string.pin_save_title_enter_pin_and_save)
|
||||
|
||||
if (usePIN2) {
|
||||
cbUseFingerprint.isChecked = true
|
||||
cbUseFingerprint.isEnabled = false
|
||||
} else {
|
||||
cbUseFingerprint.isChecked = PINStorage.haveEncryptedPIN()
|
||||
cbUseFingerprint.isEnabled = true
|
||||
}
|
||||
|
||||
// set listeners
|
||||
btn0.setOnClickListener { buttonClick(btn0) }
|
||||
btn1.setOnClickListener { buttonClick(btn1) }
|
||||
btn2.setOnClickListener { buttonClick(btn2) }
|
||||
btn3.setOnClickListener { buttonClick(btn3) }
|
||||
btn4.setOnClickListener { buttonClick(btn4) }
|
||||
btn5.setOnClickListener { buttonClick(btn5) }
|
||||
btn6.setOnClickListener { buttonClick(btn6) }
|
||||
btn7.setOnClickListener { buttonClick(btn7) }
|
||||
btn8.setOnClickListener { buttonClick(btn8) }
|
||||
btn9.setOnClickListener { buttonClick(btn9) }
|
||||
btnBackspace.setOnClickListener {
|
||||
val s = tvPin.text.toString()
|
||||
if (s.isNotEmpty())
|
||||
tvPin.text = s.substring(0, s.length - 1)
|
||||
}
|
||||
btnSavePIN.setOnClickListener { doSavePIN() }
|
||||
btnDeletePIN.setOnClickListener { doDeletePIN() }
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (fingerprintHelper != null)
|
||||
fingerprintHelper!!.cancel()
|
||||
|
||||
if (confirmWithFingerprintTask != null)
|
||||
confirmWithFingerprintTask!!.cancel(true)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
if (fingerprintHelper != null)
|
||||
fingerprintHelper!!.cancel()
|
||||
|
||||
if (confirmWithFingerprintTask != null)
|
||||
confirmWithFingerprintTask!!.cancel(true)
|
||||
}
|
||||
|
||||
override fun authenticationFailed(error: String) {
|
||||
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
override fun authenticationSucceeded(result: FingerprintManager.AuthenticationResult) {
|
||||
|
||||
cipher = result.cryptoObject.cipher
|
||||
|
||||
when (onConfirmAction) {
|
||||
PinSaveActivity.OnConfirmAction.Save -> {
|
||||
val textToEncrypt = tvPin.text.toString()
|
||||
if (usePIN2) {
|
||||
PINStorage.saveEncryptedPIN2(cipher, textToEncrypt)
|
||||
} else {
|
||||
PINStorage.saveEncryptedPIN(cipher, textToEncrypt)
|
||||
}
|
||||
}
|
||||
|
||||
PinSaveActivity.OnConfirmAction.Delete -> {
|
||||
if (usePIN2) {
|
||||
PINStorage.deleteEncryptedPIN2()
|
||||
} else {
|
||||
PINStorage.deleteEncryptedPIN()
|
||||
PINStorage.deletePIN()
|
||||
}
|
||||
tvPin.text = ""
|
||||
}
|
||||
|
||||
PinSaveActivity.OnConfirmAction.DeleteEncryptedAndSave -> if (usePIN2) {
|
||||
PINStorage.deleteEncryptedPIN2()
|
||||
PINStorage.saveEncryptedPIN2(cipher, tvPin.text.toString())
|
||||
} else {
|
||||
PINStorage.deleteEncryptedPIN()
|
||||
PINStorage.savePIN(tvPin.text.toString())
|
||||
}
|
||||
}
|
||||
|
||||
dFingerPrintConfirmation!!.dismiss()
|
||||
finish()
|
||||
}
|
||||
|
||||
fun getKeyStore(): Boolean {
|
||||
try {
|
||||
keyStore = KeyStore.getInstance(Constant.KEYSTORE)
|
||||
// create empty keystore
|
||||
keyStore!!.load(null)
|
||||
return true
|
||||
} catch (e: KeyStoreException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: CertificateException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
fun createNewKey(forceCreate: Boolean): Boolean {
|
||||
try {
|
||||
if (forceCreate)
|
||||
keyStore!!.deleteEntry(Constant.KEY_ALIAS)
|
||||
|
||||
if (!keyStore!!.containsAlias(Constant.KEY_ALIAS)) {
|
||||
val generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, Constant.KEYSTORE)
|
||||
|
||||
generator.init(KeyGenParameterSpec.Builder(Constant.KEY_ALIAS,
|
||||
KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
|
||||
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
|
||||
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
|
||||
.setUserAuthenticationRequired(true)
|
||||
.build()
|
||||
)
|
||||
|
||||
generator.generateKey()
|
||||
}
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
fun getCipher(): Boolean {
|
||||
try {
|
||||
cipher = Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/" + KeyProperties.ENCRYPTION_PADDING_PKCS7)
|
||||
return true
|
||||
} catch (e: NoSuchAlgorithmException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: NoSuchPaddingException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
fun initCipher(mode: Int): Boolean {
|
||||
try {
|
||||
keyStore!!.load(null)
|
||||
val keySpec = keyStore!!.getKey(Constant.KEY_ALIAS, null) as SecretKey
|
||||
|
||||
if (mode == Cipher.ENCRYPT_MODE) {
|
||||
cipher!!.init(mode, keySpec)
|
||||
} else {
|
||||
val iv = PINStorage.loadEncryptedIV()
|
||||
val ivSpec = IvParameterSpec(iv)
|
||||
cipher!!.init(mode, keySpec, ivSpec)
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (e: KeyPermanentlyInvalidatedException) {
|
||||
e.printStackTrace()
|
||||
// retry after clearing entry
|
||||
createNewKey(true)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
fun initCryptObject(): Boolean {
|
||||
try {
|
||||
cryptoObject = FingerprintManager.CryptoObject(cipher!!)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private fun buttonClick(button: Button) {
|
||||
tvPin.text = String.format("%s%s", tvPin.text, button.text)
|
||||
}
|
||||
|
||||
private fun doSavePIN() {
|
||||
if (confirmWithFingerprintTask != null) {
|
||||
return
|
||||
}
|
||||
|
||||
tvPin.error = null
|
||||
|
||||
val pin = tvPin.text.toString()
|
||||
|
||||
var cancel = false
|
||||
var focusView: View? = null
|
||||
|
||||
if (TextUtils.isEmpty(pin)) {
|
||||
tvPin.error = getString(R.string.error_empty_pin)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
focusView!!.requestFocus()
|
||||
} else {
|
||||
if (usePIN2) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
return
|
||||
}
|
||||
|
||||
onConfirmAction = OnConfirmAction.Save
|
||||
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
|
||||
} else {
|
||||
if (cbUseFingerprint.isChecked || PINStorage.haveEncryptedPIN()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
return
|
||||
}
|
||||
|
||||
onConfirmAction = if (cbUseFingerprint.isChecked) {
|
||||
OnConfirmAction.Save
|
||||
} else {
|
||||
OnConfirmAction.DeleteEncryptedAndSave
|
||||
}
|
||||
|
||||
// show a progress spinner, and kick off a background task to perform the user login attempt
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
PINStorage.savePIN(tvPin.text.toString())
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun doDeletePIN() {
|
||||
if (usePIN2) {
|
||||
if (PINStorage.haveEncryptedPIN2()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
return
|
||||
}
|
||||
onConfirmAction = OnConfirmAction.Delete
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
tvPin.text = ""
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
if (cbUseFingerprint.isChecked || PINStorage.haveEncryptedPIN()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
return
|
||||
}
|
||||
onConfirmAction = OnConfirmAction.Delete
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
tvPin.text = ""
|
||||
PINStorage.deletePIN()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun testFingerPrintSettings(): Boolean {
|
||||
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
fingerprintManager = getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
|
||||
|
||||
if (!keyguardManager.isKeyguardSecure) {
|
||||
Toast.makeText(baseContext, R.string.pin_save_toast_lock_screen_not_enabled, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(baseContext, R.string.pin_save_toast_no_permission_to_use_fingerprint, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
if (!fingerprintManager!!.hasEnrolledFingerprints()) {
|
||||
Toast.makeText(baseContext, R.string.pin_save_toast_no_fingerprints_registered, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,204 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_android.android.reader.NfcReader
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.card_android.data.asBundle
|
||||
import com.tangem.card_android.data.loadFromBundle
|
||||
import com.tangem.card_common.data.TangemCard
|
||||
import com.tangem.card_common.reader.CardProtocol
|
||||
import com.tangem.card_common.tasks.SwapPINTask
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_swap.*
|
||||
|
||||
class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = PinSwapActivity::class.java.simpleName
|
||||
|
||||
fun callingIntent(context: Context, newPIN: String, newPIN2: String): Intent {
|
||||
val intent = Intent(context, PinSwapActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
return intent
|
||||
}
|
||||
|
||||
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
private lateinit var card: TangemCard;
|
||||
private var newPIN: String? = null
|
||||
private var newPIN2: String? = null
|
||||
|
||||
private var progressBar: ProgressBar? = null
|
||||
|
||||
private var swapPinTask: SwapPINTask? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pin_swap)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
card = TangemCard(intent.getStringExtra(EXTRA_TANGEM_CARD_UID))
|
||||
|
||||
card.loadFromBundle(intent.extras!!.getBundle(EXTRA_TANGEM_CARD))
|
||||
|
||||
newPIN = intent.getStringExtra(Constant.EXTRA_NEW_PIN)
|
||||
newPIN2 = intent.getStringExtra(Constant.EXTRA_NEW_PIN_2)
|
||||
|
||||
tvCardID.text = card.cidDescription
|
||||
|
||||
progressBar = findViewById(R.id.progressBar)
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
// get IsoDep handle and run cardReader thread
|
||||
val isoDep = IsoDep.get(tag)
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (sUID == card.uid) {
|
||||
isoDep.timeout = card.pauseBeforePIN2 + 65000
|
||||
swapPinTask = SwapPINTask(card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this, newPIN, newPIN2)
|
||||
swapPinTask?.start()
|
||||
} else {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
swapPinTask?.cancel(true)
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
swapPinTask?.cancel(true)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
progressBar?.post {
|
||||
progressBar?.visibility = View.VISIBLE
|
||||
progressBar?.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadFinish(cardProtocol: CardProtocol?) {
|
||||
swapPinTask = null
|
||||
|
||||
if (cardProtocol != null) {
|
||||
when {
|
||||
cardProtocol.error == null -> progressBar!!.post {
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.GREEN)
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
cardProtocol.error is CardProtocol.TangemException_InvalidPIN -> {
|
||||
progressBar!!.post {
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
progressBar!!.postDelayed({
|
||||
try {
|
||||
progressBar!!.progress = 0
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, "Cannot change PIN(s). Make sure you enter correct PIN2!")
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
setResult(RESULT_INVALID_PIN, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
else -> progressBar!!.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed) {
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(baseContext, R.string.general_notification_scan_again, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
}
|
||||
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadProgress(protocol: CardProtocol, progress: Int) {
|
||||
progressBar!!.post { progressBar!!.progress = progress }
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
swapPinTask = null
|
||||
|
||||
progressBar!!.postDelayed({
|
||||
try {
|
||||
progressBar!!.progress = 0
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar!!.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.CryptonitOtherApi
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_other_api_withdrawal.*
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareCryptonitOtherApiWithdrawalActivity::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var cryptonit: CryptonitOtherApi? = null
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_prepare_cryptonit_other_api_withdrawal)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
cryptonit = CryptonitOtherApi(this)
|
||||
|
||||
tvKey.text = cryptonit!!.key
|
||||
tvUserID.text = cryptonit!!.userId
|
||||
tvSecret.text = cryptonit!!.secretDescription
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
etAmount.filters = engine.amountInputFilters
|
||||
|
||||
// set listeners
|
||||
btnLoad.setOnClickListener {
|
||||
try {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
// if (!engine.checkAmount(card, strAmount))
|
||||
// etAmount.error = getString(R.string.unknown_amount_format)
|
||||
val dblAmount: Double = strAmount.toDouble()
|
||||
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestCryptoWithdrawal(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.prepare_transaction_error_unknown_amount_format)
|
||||
}
|
||||
|
||||
//Toast.makeText(this, strAmount, Toast.LENGTH_LONG).show()
|
||||
// val balance = engine.getBalanceLong(card)!! / (card!!.blockchain.multiplier / 1000.0)
|
||||
// if (etAmount.text.toString().replace(",", ".").toDouble() > balance) {
|
||||
// etAmount.error = getString(R.string.not_enough_funds_on_your_account)
|
||||
// return@setOnClickListener
|
||||
// }
|
||||
|
||||
}
|
||||
ivCameraKey.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_KEY) }
|
||||
|
||||
ivCameraSecret.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_SECRET) }
|
||||
|
||||
ivCameraUserId.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_USER_ID) }
|
||||
|
||||
ivRefreshBalance.setOnClickListener { doRequestBalance() }
|
||||
|
||||
cryptonit!!.setBalanceListener { response ->
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
|
||||
tvBalance.text = response.eth_available
|
||||
}
|
||||
Blockchain.Bitcoin, Blockchain.BitcoinTestNet, Blockchain.BitcoinCash -> {
|
||||
tvBalance.text = response.btc_available
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
tvBalanceCurrency.text = ctx.blockchain.currency
|
||||
tvBalance.setTextColor(Color.BLACK)
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
btnLoad.isActivated = true
|
||||
}
|
||||
cryptonit!!.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
cryptonit!!.setWithdrawalListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.success != null && response.success!!) finish()
|
||||
else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = response.reason!!.toString()
|
||||
}
|
||||
}
|
||||
btnLoad.isActivated = false
|
||||
doRequestBalance()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.extras!!.containsKey("QRCode")) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_SCAN_QR_KEY -> {
|
||||
cryptonit!!.key = data.getStringExtra("QRCode")
|
||||
tvKey!!.text = cryptonit!!.key
|
||||
}
|
||||
Constant.REQUEST_CODE_SCAN_QR_SECRET -> {
|
||||
cryptonit!!.secret = data.getStringExtra("QRCode")
|
||||
tvSecret!!.text = cryptonit!!.secretDescription
|
||||
}
|
||||
Constant.REQUEST_CODE_SCAN_QR_USER_ID -> {
|
||||
cryptonit!!.userId = data.getStringExtra("QRCode")
|
||||
tvUserID!!.text = cryptonit!!.userId
|
||||
}
|
||||
}
|
||||
cryptonit!!.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doRequestBalance() {
|
||||
if (cryptonit!!.havaAccountInfo()) {
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
cryptonit!!.requestBalance(ctx.blockchain.currency, "USD")
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.text.InputFilter
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.Cryptonit
|
||||
import com.tangem.util.DecimalDigitsInputFilter
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_withdrawal.*
|
||||
import java.io.IOException
|
||||
|
||||
class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareCryptonitWithdrawalActivity::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
private var cryptonit: Cryptonit? = null
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_prepare_cryptonit_withdrawal)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
cryptonit = Cryptonit(this)
|
||||
|
||||
etUsername.setText(cryptonit!!.username)
|
||||
etPassword.setText(cryptonit!!.password)
|
||||
etFee.setText(cryptonit!!.fee)
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
tvFeeCurrency.text = engine.feeCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
etAmount.filters = engine.amountInputFilters
|
||||
|
||||
etAmount.setOnEditorActionListener { lv, actionId, _ ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
val imm = lv.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(lv.windowToken, 0)
|
||||
true
|
||||
} else
|
||||
false
|
||||
}
|
||||
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Bitcoin -> {
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
etFee.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(5))
|
||||
}
|
||||
Blockchain.BitcoinCash -> {
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
etFee.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(8))
|
||||
}
|
||||
Blockchain.Ethereum -> {
|
||||
etAmount.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(18))
|
||||
etFee.filters = arrayOf<InputFilter>(DecimalDigitsInputFilter(18))
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
|
||||
// set listeners
|
||||
btnLoad.setOnClickListener {
|
||||
try {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
val strFee: String = etFee.text.toString().replace(",", ".")
|
||||
val dblAmount: Double = strAmount.toDouble()
|
||||
cryptonit!!.fee = strFee
|
||||
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestWithdrawCoins(ctx.blockchain.currency, dblAmount, ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.prepare_transaction_error_unknown_amount_format)
|
||||
}
|
||||
}
|
||||
|
||||
ivRefreshBalance.setOnClickListener {
|
||||
cryptonit!!.username = etUsername.text.toString()
|
||||
cryptonit!!.password = etPassword.text.toString()
|
||||
cryptonit!!.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
|
||||
cryptonit!!.setBalanceListener { response ->
|
||||
tvBalance.text = response.results[0].balance.toString()
|
||||
tvBalanceCurrency.text = response.results[0].currency // card!!.blockchain.currency
|
||||
tvBalance.setTextColor(Color.BLACK)
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
btnLoad.visibility = View.VISIBLE
|
||||
}
|
||||
cryptonit!!.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
cryptonit!!.setWithdrawalListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.success != null && response.success!!) {
|
||||
Toast.makeText(this, R.string.withdrawal_successful, Toast.LENGTH_LONG).show();
|
||||
finish()
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = response.errors.toString()
|
||||
}
|
||||
}
|
||||
btnLoad.visibility = View.INVISIBLE
|
||||
doRequestBalance()
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doRequestBalance() {
|
||||
if (cryptonit!!.haveAccountInfo()) {
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
cryptonit!!.requestBalance(ctx.blockchain.currency)
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,258 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.Kraken
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_prepare_kraken_withdrawal.*
|
||||
import java.io.IOException
|
||||
import java.math.BigDecimal
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareKrakenWithdrawalActivity::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
|
||||
private var kraken: Kraken? = null
|
||||
private var fee: BigDecimal? = null
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_prepare_kraken_withdrawal)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
kraken = Kraken(this)
|
||||
|
||||
tvKey.text = kraken!!.key
|
||||
tvSecret.text = kraken!!.secretDescription
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvCurrency.text = engine!!.balanceCurrency
|
||||
|
||||
etAmount.setText(engine.convertToAmount(engine.convertToInternalAmount(ctx.card!!.denomination)).toValueString())
|
||||
etAmount.filters = engine.amountInputFilters
|
||||
|
||||
etAmount.setOnEditorActionListener { lv, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE) {
|
||||
val imm = lv.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
imm.hideSoftInputFromWindow(lv.windowToken, 0)
|
||||
lv.clearFocus()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// set listeners
|
||||
btnLoad.setOnClickListener {
|
||||
try {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
|
||||
var dblAmount: Double = strAmount.toDouble()
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
kraken!!.requestWithdrawInfo(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.prepare_transaction_error_unknown_amount_format)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ivCamera.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR) }
|
||||
|
||||
ivRefreshBalance.setOnClickListener { doRequestBalance() }
|
||||
|
||||
kraken!!.setBalanceListener { response ->
|
||||
if (response.error != null && response.error.isNotEmpty()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = Arrays.toString(response.error)
|
||||
} else {
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Ethereum -> {
|
||||
tvBalance.text = response.result.XETH.trimEnd('0')
|
||||
}
|
||||
Blockchain.Bitcoin -> {
|
||||
tvBalance.text = response.result.XXBT.trimEnd('0')
|
||||
}
|
||||
Blockchain.BitcoinCash -> {
|
||||
tvBalance.text = response.result.BCH.trimEnd('0')
|
||||
}
|
||||
else -> {
|
||||
tvBalance.text = "???"
|
||||
}
|
||||
}
|
||||
tvBalanceCurrency.text = ctx.blockchain.currency
|
||||
tvBalance.setTextColor(Color.BLACK)
|
||||
btnLoad.visibility = View.VISIBLE
|
||||
}
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
kraken!!.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
kraken!!.setWithdrawalListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.error != null && response.error.isNotEmpty()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = Arrays.toString(response.error)
|
||||
} else {
|
||||
Toast.makeText(this, "Withdrawal successful!", Toast.LENGTH_LONG).show()
|
||||
finish()
|
||||
}
|
||||
}
|
||||
kraken!!.setWithdrawalInfoListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.error != null && response.error.isNotEmpty()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = Arrays.toString(response.error)
|
||||
} else {
|
||||
fee = BigDecimal(response.result.fee)
|
||||
showConfirmDialog()
|
||||
}
|
||||
}
|
||||
|
||||
btnLoad.visibility = View.INVISIBLE
|
||||
doRequestBalance()
|
||||
}
|
||||
|
||||
// Method to show an alert dialog with yes, no and cancel button
|
||||
private fun showConfirmDialog() {
|
||||
// Late initialize an alert dialog object
|
||||
lateinit var dialog: AlertDialog
|
||||
|
||||
|
||||
// Initialize a new instance of alert dialog builder object
|
||||
val builder = AlertDialog.Builder(this)
|
||||
|
||||
// Set a title for alert dialog
|
||||
builder.setTitle(R.string.kraken_please_confirm_withdraw)
|
||||
|
||||
// Set a message for alert dialog
|
||||
builder.setMessage(String.format("Continue with fee %s %s?", fee!!.toString().trimEnd('0'), ctx.blockchain.currency))
|
||||
|
||||
// On click listener for dialog buttons
|
||||
val dialogClickListener = DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
try {
|
||||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
|
||||
var dblAmount: Double = strAmount.toDouble()
|
||||
|
||||
dblAmount += fee!!.toDouble()
|
||||
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
kraken!!.requestWithdraw(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.prepare_transaction_error_unknown_amount_format)
|
||||
}
|
||||
}
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
Toast.makeText(this, R.string.kraken_operation_canceled, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the alert dialog positive/yes button
|
||||
builder.setPositiveButton(R.string.general_yes, dialogClickListener)
|
||||
|
||||
// Set the alert dialog negative/no button
|
||||
builder.setNegativeButton(R.string.general_no, dialogClickListener)
|
||||
|
||||
|
||||
// Initialize the AlertDialog using builder object
|
||||
dialog = builder.create()
|
||||
|
||||
// Finally, display the alert dialog
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
private fun doRequestBalance() {
|
||||
if (kraken!!.haveAccountInfo()) {
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
kraken!!.requestBalance()
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.kraken_not_enough_account_data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.extras!!.containsKey("QRCode")) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_SCAN_QR -> {
|
||||
val uri = URI(data.getStringExtra("QRCode"))
|
||||
val query = uri.query
|
||||
val params = query.split("&")
|
||||
for (param in params) {
|
||||
if (param.startsWith("key=")) kraken!!.key = param.substring(4)
|
||||
else if (param.startsWith("secret=")) kraken!!.secret = param.substring(7)
|
||||
}
|
||||
tvKey!!.text = kraken!!.key
|
||||
tvSecret!!.text = kraken!!.secretDescription
|
||||
}
|
||||
}
|
||||
kraken!!.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcDeviceAntennaLocation
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_android.android.reader.NfcReader
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.card_android.data.asBundle
|
||||
import com.tangem.card_common.reader.CardProtocol
|
||||
import com.tangem.card_common.tasks.PurgeTask
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialogNew
|
||||
import com.tangem.ui.event.DeletingWalletFinish
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.activity_purge.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import javax.inject.Inject
|
||||
|
||||
class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = PurgeActivity::class.java.simpleName
|
||||
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, PurgeActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
|
||||
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
@Inject
|
||||
internal lateinit var waitSecurityDelayDialogNew: WaitSecurityDelayDialogNew
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private lateinit var nfcDeviceAntenna: NfcDeviceAntennaLocation
|
||||
|
||||
private var purgeTask: PurgeTask? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_purge)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
|
||||
// init NFC Antenna
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(this, ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna.init()
|
||||
|
||||
tvCardID.text = ctx.card.cidDescription
|
||||
progressBar.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
purgeTask?.cancel(true)
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
// get IsoDep handle and run cardReader thread
|
||||
val isoDep = IsoDep.get(tag)
|
||||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (sUID == ctx.card.uid) {
|
||||
isoDep.timeout = ctx.card.pauseBeforePIN2 + 65000
|
||||
purgeTask = PurgeTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this)
|
||||
purgeTask?.start()
|
||||
} else {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
|
||||
// val readWait = ReadWait()
|
||||
// readWait.msec = msec
|
||||
// EventBus.getDefault().post(readWait)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
|
||||
// if (!waitSecurityDelayDialogNew.isAdded)
|
||||
// waitSecurityDelayDialogNew.show(supportFragmentManager, WaitSecurityDelayDialogNew.TAG)
|
||||
//
|
||||
//
|
||||
// val readBeforeRequest = ReadBeforeRequest()
|
||||
// readBeforeRequest.timeout = timeout
|
||||
// EventBus.getDefault().post(readBeforeRequest)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
|
||||
// val readAfterRequest = ReadAfterRequest()
|
||||
// EventBus.getDefault().post(readAfterRequest)
|
||||
}
|
||||
|
||||
override fun onReadStart(cardProtocol: CardProtocol) {
|
||||
rlProgressBar.post { rlProgressBar.visibility = View.VISIBLE }
|
||||
|
||||
progressBar.post {
|
||||
progressBar.visibility = View.VISIBLE
|
||||
progressBar.progress = 5
|
||||
}
|
||||
}
|
||||
|
||||
override fun onReadFinish(cardProtocol: CardProtocol?) {
|
||||
purgeTask = null
|
||||
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
rlProgressBar.post { rlProgressBar.visibility = View.GONE }
|
||||
|
||||
progressBar?.post {
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.GREEN)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
setResult(Activity.RESULT_OK, intent)
|
||||
|
||||
EventBus.getDefault().post(DeletingWalletFinish())
|
||||
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_InvalidPIN) {
|
||||
progressBar?.post {
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
intent.putExtra(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, getString(R.string.nfc_error_cannot_erase_wallet))
|
||||
setResult(RESULT_INVALID_PIN, intent)
|
||||
finish()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
} else {
|
||||
progressBar?.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed)
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
} else
|
||||
Toast.makeText(baseContext, R.string.general_notification_scan_again_to_verify, Toast.LENGTH_LONG).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rlProgressBar?.postDelayed({
|
||||
try {
|
||||
rlProgressBar.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
override fun onReadProgress(protocol: CardProtocol, progress: Int) {
|
||||
progressBar?.post { progressBar?.progress = progress }
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
purgeTask = null
|
||||
progressBar?.postDelayed({
|
||||
try {
|
||||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.google.zxing.Result
|
||||
import com.tangem.Constant
|
||||
import me.dm7.barcodescanner.zxing.ZXingScannerView
|
||||
|
||||
class QrScanActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {
|
||||
companion object {
|
||||
fun callingIntent(context: Context): Intent {
|
||||
return Intent(context, QrScanActivity::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
private var scannerView: ZXingScannerView? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), 1)
|
||||
else
|
||||
runScanner()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
scannerView?.stopCamera()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
scannerView?.startCamera()
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
||||
when (requestCode) {
|
||||
1 -> {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
runScanner()
|
||||
else {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleResult(result: Result) {
|
||||
val data = Intent()
|
||||
data.putExtra(Constant.EXTRA_QR_CODE, result.text)
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun runScanner() {
|
||||
// programmatically initialize the scanner view
|
||||
scannerView = ZXingScannerView(this)
|
||||
setContentView(scannerView)
|
||||
|
||||
// register ourselves as a handler for scan results.
|
||||
scannerView?.setResultHandler(this)
|
||||
scannerView?.startCamera()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.content.Intent
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.view.KeyEvent
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.ui.event.TransactionFinishWithError
|
||||
import com.tangem.ui.event.TransactionFinishWithSuccess
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.CoinEngine
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import java.io.IOException
|
||||
|
||||
class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var tx: ByteArray? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_send_transaction)
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
tx = intent.getByteArrayExtra(Constant.EXTRA_TX)
|
||||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
engine!!.requestSendTransaction(
|
||||
object : CoinEngine.BlockchainRequestsCallbacks {
|
||||
override fun onComplete(success: Boolean) {
|
||||
if (success) {
|
||||
App.pendingTransactionsStorage.putTransaction(ctx.card, Util.bytesToHex(tx), engine.pendingTransactionTimeoutInSeconds())
|
||||
finishWithSuccess()
|
||||
}else
|
||||
finishWithError(ctx.error)
|
||||
}
|
||||
|
||||
override fun onProgress() {
|
||||
}
|
||||
|
||||
override fun allowAdvance(): Boolean {
|
||||
return UtilHelper.isOnline(this@SendTransactionActivity)
|
||||
}
|
||||
},
|
||||
tx
|
||||
)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> {
|
||||
Toast.makeText(this, R.string.send_transaction_notification_wait, Toast.LENGTH_LONG).show()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun finishWithSuccess() {
|
||||
val transactionFinishWithSuccess = TransactionFinishWithSuccess()
|
||||
transactionFinishWithSuccess.message = getString(R.string.send_transaction_success)
|
||||
EventBus.getDefault().post(transactionFinishWithSuccess)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, getString(R.string.send_transaction_success))
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun finishWithError(message: String) {
|
||||
val transactionFinishWithError = TransactionFinishWithError()
|
||||
transactionFinishWithError.message = String.format(getString(R.string.send_transaction_error_failed_to_send), message)
|
||||
EventBus.getDefault().post(transactionFinishWithError)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, String.format(getString(R.string.send_transaction_error_failed_to_send), message))
|
||||
setResult(RESULT_CANCELED, intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import com.tangem.wallet.R
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
companion object {
|
||||
fun callingIntent(context: Context) = Intent(context, SettingsActivity::class.java)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
||||
initToolbar()
|
||||
}
|
||||
|
||||
private fun initToolbar() {
|
||||
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
||||
toolbar.setTitle(R.string.settings_title)
|
||||
toolbar.setNavigationIcon(android.R.drawable.ic_menu_close_clear_cancel)
|
||||
setSupportActionBar(toolbar)
|
||||
toolbar.setNavigationOnClickListener { finish() }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package com.tangem.ui.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.ui.fragment.VerifyCard
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class VerifyCardActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var navigator: Navigator
|
||||
|
||||
companion object {
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, VerifyCardActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_verify_card)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
super.onBackPressed()
|
||||
val verifyCard = supportFragmentManager.findFragmentById(R.id.verify_card_fragment) as VerifyCard
|
||||
val data = verifyCard.prepareResultIntent()
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue