Updated on 2026-08-14

This commit is contained in:
Tangem 2018-12-19 17:31:11 +03:00
commit a69588389a
9 changed files with 78 additions and 87 deletions

View file

@ -1,5 +1,7 @@
package com.tangem
import android.app.Activity
object Constant {
const val EXTRA_BLOCKCHAIN_DATA = "BLOCKCHAIN_DATA"
@ -44,4 +46,12 @@ object Constant {
const val EXTRA_NEW_PIN = "newPIN"
const val EXTRA_NEW_PIN_2 = "newPIN2"
// CreateNewWalletActivity
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
// EmptyWalletActivity
const val REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY = 2
const val REQUEST_CODE_REQUEST_PIN2 = 3
}

View file

@ -56,16 +56,16 @@ class Navigator {
context.startActivityForResult(PinSwapActivity.callingIntent(context, newPIN, newPIN2), Constant.REQUEST_CODE_SWAP_PIN)
}
fun showPurge(context: Activity) {
fun showPurge(context: Activity, ctx: TangemContext) {
context.startActivityForResult(PurgeActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_PURGE)
}
fun showPreparePayment(context: Activity, ctx: TangemContext) {
context.startActivityForResult(PreparePaymentActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_SEND_PAYMENT)
}
fun showCreateNewWallet(context: Activity) {
fun showCreateNewWallet(context: Activity, ctx: TangemContext) {
context.startActivityForResult(CreateNewWalletActivity.callingIntent(context, ctx), Constant.REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY)
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.presentation.activity
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Color
@ -13,24 +14,28 @@ import android.view.View
import android.widget.ProgressBar
import android.widget.Toast
import com.tangem.App
import com.tangem.tangemcard.tasks.CreateNewWalletTask
import com.tangem.tangemcard.reader.CardProtocol
import com.tangem.tangemcard.android.reader.NfcManager
import com.tangem.Constant
import com.tangem.domain.wallet.TangemContext
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog
import com.tangem.presentation.dialog.WaitSecurityDelayDialog
import com.tangem.tangemcard.android.reader.NfcManager
import com.tangem.tangemcard.android.reader.NfcReader
import com.tangem.tangemcard.util.Util
import com.tangem.tangemcard.data.asBundle
import com.tangem.tangemcard.reader.CardProtocol
import com.tangem.tangemcard.tasks.CreateNewWalletTask
import com.tangem.tangemcard.util.Util
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.activity_create_new_wallet.*
class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
companion object {
val TAG: String = CreateNewWalletActivity::class.java.simpleName
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
fun callingIntent(context: Context, ctx: TangemContext): Intent {
val intent = Intent(context, EmptyWalletActivity::class.java)
intent.putExtra("UID", ctx.card!!.uid)
intent.putExtra("Card", ctx.card!!.asBundle)
return intent
}
}
private lateinit var ctx: TangemContext
@ -45,8 +50,6 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_create_new_wallet)
// MainActivity.commonInit(applicationContext)
nfcManager = NfcManager(this, this)
ctx = TangemContext.loadFromBundle(this, intent.extras)
@ -73,11 +76,11 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
} else {
isoDep.timeout = ctx.card!!.pauseBeforePIN2 + 65000
}
createNewWalletTask = CreateNewWalletTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage,this)
createNewWalletTask = CreateNewWalletTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this)
createNewWalletTask!!.start()
} else {
// Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + mCard.getUID() + ")");
nfcManager!!.ignoreTag(isoDep.tag)
nfcManager.ignoreTag(isoDep.tag)
}
} catch (e: Exception) {
@ -87,11 +90,11 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
public override fun onResume() {
super.onResume()
nfcManager!!.onResume()
nfcManager.onResume()
}
public override fun onPause() {
nfcManager!!.onPause()
nfcManager.onPause()
if (createNewWalletTask != null)
createNewWalletTask!!.cancel(true)
super.onPause()
@ -99,7 +102,7 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
public override fun onStop() {
// dismiss enable NFC dialog
nfcManager!!.onStop()
nfcManager.onStop()
if (createNewWalletTask != null)
createNewWalletTask!!.cancel(true)
super.onStop()
@ -141,7 +144,7 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
intent.putExtra("message", "Cannot create wallet. Make sure you enter correct PIN2!")
intent.putExtra("UID", cardProtocol.card.uid)
intent.putExtra("Card", cardProtocol.card!!.asBundle)
setResult(RESULT_INVALID_PIN, intent)
setResult(Constant.RESULT_INVALID_PIN, intent)
finish()
} catch (e: Exception) {
e.printStackTrace()
@ -179,7 +182,6 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
}
override fun onReadCancel() {
createNewWalletTask = null
progressBar!!.postDelayed({

View file

@ -14,6 +14,8 @@ import android.text.Html
import android.view.View
import android.widget.Toast
import com.tangem.App
import com.tangem.Constant
import com.tangem.di.Navigator
import com.tangem.tangemcard.tasks.VerifyCardTask
import com.tangem.tangemcard.reader.CardProtocol
import com.tangem.tangemcard.android.reader.NfcManager
@ -27,18 +29,13 @@ import com.tangem.tangemcard.data.loadFromBundle
import com.tangem.tangemcard.util.Util
import com.tangem.wallet.R
import kotlinx.android.synthetic.main.activity_empty_wallet.*
import javax.inject.Inject
class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
companion object {
val TAG: String = EmptyWalletActivity::class.java.simpleName
private const val REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY = 2
private const val REQUEST_CODE_REQUEST_PIN2 = 3
private const val REQUEST_CODE_VERIFY_CARD = 4
fun callingIntent(context: Context, ctx: TangemContext) : Intent {
val intent=Intent(context, EmptyWalletActivity::class.java)
fun callingIntent(context: Context, ctx: TangemContext): Intent {
val intent = Intent(context, EmptyWalletActivity::class.java)
ctx.saveToIntent(intent)
return intent
}
@ -50,11 +47,14 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
private var verifyCardTask: VerifyCardTask? = null
private var requestPIN2Count = 0
@Inject
internal lateinit var navigator: Navigator
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_empty_wallet)
// MainActivity.commonInit(applicationContext)
App.getNavigatorComponent().inject(this)
nfcManager = NfcManager(this, this)
@ -105,27 +105,27 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
intent.putExtra("UID", ctx.card!!.uid)
intent.putExtra("Card", ctx.card!!.asBundle)
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2)
}
}
public override fun onResume() {
super.onResume()
nfcManager!!.onResume()
nfcManager.onResume()
}
public override fun onPause() {
super.onPause()
nfcManager!!.onPause()
nfcManager.onPause()
}
public override fun onStop() {
super.onStop()
nfcManager!!.onStop()
nfcManager.onStop()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY) {
if (requestCode == Constant.REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
@ -140,21 +140,22 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
updatedCard.loadFromBundle(data.getBundleExtra("Card"))
ctx.card = updatedCard
}
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
requestPIN2Count++
val intent = Intent(baseContext, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
intent.putExtra("UID", ctx.card!!.uid)
intent.putExtra("Card", ctx.card!!.asBundle)
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2)
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2)
return
}
}
setResult(resultCode, data)
finish()
} else if (requestCode == REQUEST_CODE_REQUEST_PIN2) {
} else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2) {
if (resultCode == Activity.RESULT_OK) {
doCreateNewWallet()
// doCreateNewWallet()
navigator.showCreateNewWallet(this, ctx)
}
}
}
@ -167,7 +168,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
val sUID = Util.byteArrayToHexString(uid)
if (ctx.card!!.uid != sUID) {
// Log.d(TAG, "Invalid UID: " + sUID);
nfcManager!!.ignoreTag(isoDep.tag)
nfcManager.ignoreTag(isoDep.tag)
return
} else {
// Log.v(TAG, "UID: " + sUID);
@ -263,11 +264,4 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
WaitSecurityDelayDialog.onReadAfterRequest(this)
}
private fun doCreateNewWallet() {
val intent = Intent(this, CreateNewWalletActivity::class.java)
intent.putExtra("UID", ctx.card!!.uid)
intent.putExtra("Card", ctx.card!!.asBundle)
startActivityForResult(intent, REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY)
}
}

View file

@ -57,17 +57,6 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
val TAG: String = MainActivity::class.java.simpleName
fun callingIntent(context: Context) = Intent(context, MainActivity::class.java)
// fun commonInit(context: Context) {
// if (PINStorage.needInit())
// PINStorage.init(context)
//
// if (Issuer.needInit())
// Issuer.init(context)
//
// if (Firmwares.needInit())
// Firmwares.init(context)
// }
}
private lateinit var nfcManager: NfcManager
@ -104,8 +93,6 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR
// commonInit(applicationContext)
setNfcAdapterReaderCallback(this)
rippleBackgroundNfc.startRippleAnimation()
@ -307,7 +294,7 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
readCardInfoTask = null
if (cardProtocol != null) {
if (cardProtocol.error == null) {
nfcManager!!.notifyReadResult(true)
nfcManager.notifyReadResult(true)
rlProgressBar.post {
rlProgressBar.visibility = View.GONE
@ -354,7 +341,7 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
lastTag = null
ReadCardInfoTask.resetLastReadInfo()
nfcManager!!.notifyReadResult(false)
nfcManager.notifyReadResult(false)
}
}
}

View file

@ -1,6 +1,7 @@
package com.tangem.presentation.activity
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.res.ColorStateList
@ -30,6 +31,12 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
companion object {
val TAG: String = PurgeActivity::class.java.simpleName
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
fun callingIntent(context: Context, ctx: TangemContext): Intent {
val intent = Intent(context, PurgeActivity::class.java)
ctx.saveToIntent(intent)
return intent
}
}
private lateinit var ctx: TangemContext
@ -53,18 +60,18 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
public override fun onResume() {
super.onResume()
nfcManager?.onResume()
nfcManager.onResume()
}
public override fun onPause() {
nfcManager?.onPause()
nfcManager.onPause()
purgeTask?.cancel(true)
super.onPause()
}
public override fun onStop() {
// dismiss enable NFC dialog
nfcManager?.onStop()
nfcManager.onStop()
purgeTask?.cancel(true)
super.onStop()
}
@ -72,8 +79,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
override fun onTagDiscovered(tag: Tag) {
try {
// get IsoDep handle and run cardReader thread
val isoDep = IsoDep.get(tag)
?: throw CardProtocol.TangemException(getString(R.string.wrong_tag_err))
val isoDep = IsoDep.get(tag) ?: throw CardProtocol.TangemException(getString(R.string.wrong_tag_err))
val uid = tag.id
val sUID = Util.byteArrayToHexString(uid)
// Log.v(TAG, "UID: $sUID")
@ -84,7 +90,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
purgeTask!!.start()
} else {
// this Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + card.getUID() + ")");
nfcManager?.ignoreTag(isoDep.tag)
nfcManager.ignoreTag(isoDep.tag)
}
} catch (e: Exception) {

View file

@ -30,8 +30,6 @@ class VerifyCardActivity : AppCompatActivity() {
setContentView(R.layout.activity_verify_card)
App.getNavigatorComponent().inject(this)
// MainActivity.commonInit(applicationContext)
}
override fun onBackPressed() {

View file

@ -350,7 +350,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
updatedCard.loadFromBundle(data.getBundleExtra(EXTRA_TANGEM_CARD))
ctx.card = updatedCard
}
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
requestPIN2Count++
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
@ -364,11 +364,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
}
}
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK) {
val intent = Intent(activity, PurgeActivity::class.java)
ctx.saveToIntent(intent)
startActivityForResult(intent, Constant.REQUEST_CODE_PURGE)
}
// TODO unused block, need check and remove it
// Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK)
// (activity as LoadedWalletActivity).navigator.showPurge(context as Activity, ctx)
Constant.REQUEST_CODE_PURGE -> if (resultCode == Activity.RESULT_OK) {
if (data == null) {
@ -387,7 +385,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
updatedCard.loadFromBundle(data.getBundleExtra(EXTRA_TANGEM_CARD))
ctx.card = updatedCard
}
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
requestPIN2Count++
val intent = Intent(activity, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())

View file

@ -19,10 +19,7 @@ import com.tangem.Constant
import com.tangem.data.Blockchain
import com.tangem.domain.wallet.CoinEngineFactory
import com.tangem.domain.wallet.TangemContext
import com.tangem.presentation.activity.CreateNewWalletActivity
import com.tangem.presentation.activity.PinRequestActivity
import com.tangem.presentation.activity.PurgeActivity
import com.tangem.presentation.activity.VerifyCardActivity
import com.tangem.presentation.activity.*
import com.tangem.presentation.dialog.PINSwapWarningDialog
import com.tangem.tangemcard.android.data.PINStorage
import com.tangem.tangemcard.android.reader.NfcManager
@ -158,7 +155,7 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
updatedCard.loadFromBundle(data.getBundleExtra("Card"))
ctx.card = updatedCard
}
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
requestPIN2Count++
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra("mode", PinRequestActivity.Mode.RequestPIN2.toString())
@ -171,11 +168,10 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
}
}
}
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK) {
val intent = Intent(context, PurgeActivity::class.java)
ctx.saveToIntent(intent)
startActivityForResult(intent, Constant.REQUEST_CODE_PURGE)
}
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK)
(activity as VerifyCardActivity).navigator.showPurge(context as Activity, ctx)
Constant.REQUEST_CODE_PURGE -> if (resultCode == Activity.RESULT_OK) {
if (data == null) {
data = Intent()
@ -192,7 +188,7 @@ class VerifyCard : Fragment(), NfcAdapter.ReaderCallback {
updatedCard.loadFromBundle(data.getBundleExtra("Card"))
ctx.card = updatedCard
}
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
requestPIN2Count++
val intent = Intent(context, PinRequestActivity::class.java)
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())