From ec01bdcffe05b2dda2a1191476a127d6d3912e41 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 28 Jan 2019 13:03:52 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../activity/EmptyWalletActivity.kt | 119 +++++++++--------- .../presentation/fragment/LoadedWallet.kt | 5 +- .../main/res/layout/activity_empty_wallet.xml | 43 +------ app/src/main/res/layout/fr_loaded_wallet.xml | 3 +- .../main/res/layout/layout_tangem_card.xml | 2 +- 5 files changed, 64 insertions(+), 108 deletions(-) diff --git a/app/src/main/java/com/tangem/presentation/activity/EmptyWalletActivity.kt b/app/src/main/java/com/tangem/presentation/activity/EmptyWalletActivity.kt index f20c3a6ca8..c49bbbc8ba 100644 --- a/app/src/main/java/com/tangem/presentation/activity/EmptyWalletActivity.kt +++ b/app/src/main/java/com/tangem/presentation/activity/EmptyWalletActivity.kt @@ -28,6 +28,7 @@ import com.tangem.tangemcard.reader.CardProtocol import com.tangem.tangemcard.tasks.VerifyCardTask import com.tangem.tangemcard.util.Util import com.tangem.util.LOG +import com.tangem.util.UtilHelper import com.tangem.wallet.R import kotlinx.android.synthetic.main.activity_empty_wallet.* import kotlinx.android.synthetic.main.layout_tangem_card.* @@ -53,6 +54,8 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card 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) @@ -63,8 +66,6 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card ctx = TangemContext.loadFromBundle(this, intent.extras) - - tvIssuer.text = ctx.card!!.issuerDescription if (ctx.card!!.tokenSymbol.length > 1) { @@ -76,33 +77,6 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card tvCardID.text = ctx.card!!.cidDescription ivTangemCard.setImageBitmap(App.localStorage.getCardArtworkBitmap(ctx.card)) - if (ctx.card!!.useDefaultPIN1()) { - imgPIN.setImageResource(R.drawable.unlock_pin1) - imgPIN.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_default_PIN1_code, Toast.LENGTH_LONG).show() } - } else { - imgPIN.setImageResource(R.drawable.lock_pin1) - imgPIN.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_user_PIN1_code, Toast.LENGTH_LONG).show() } - } - - if (ctx.card!!.pauseBeforePIN2 > 0 && (ctx.card!!.useDefaultPIN2()!! || !ctx.card!!.useSmartSecurityDelay())) { - imgPIN2orSecurityDelay.setImageResource(R.drawable.timer) - imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, String.format(getString(R.string.this_banknote_will_enforce), ctx.card!!.pauseBeforePIN2 / 1000.0), Toast.LENGTH_LONG).show() } - - } else if (ctx.card!!.useDefaultPIN2()!!) { - imgPIN2orSecurityDelay.setImageResource(R.drawable.unlock_pin2) - imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_default_PIN2_code, Toast.LENGTH_LONG).show() } - } else { - imgPIN2orSecurityDelay.setImageResource(R.drawable.lock_pin2) - imgPIN2orSecurityDelay.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.this_banknote_protected_user_PIN2_code, Toast.LENGTH_LONG).show() } - } - - if (ctx.card!!.useDevelopersFirmware()!!) { - imgDeveloperVersion.setImageResource(R.drawable.ic_developer_version) - imgDeveloperVersion.visibility = View.VISIBLE - imgDeveloperVersion.setOnClickListener { Toast.makeText(this@EmptyWalletActivity, R.string.unlocked_banknote_only_development_use, Toast.LENGTH_LONG).show() } - } else - imgDeveloperVersion.visibility = View.INVISIBLE - // set listeners btnNewWallet.setOnClickListener { requestPIN2Count = 0 @@ -112,6 +86,13 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card intent.putExtra("Card", ctx.card!!.asBundle) startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2) } + + btnDetails.setOnClickListener { + if (cardProtocol != null) + navigator.showVerifyCard(this, ctx) + else + UtilHelper.showSingleToast(this, getString(R.string.need_attach_card_again)) + } } public override fun onResume() { @@ -132,7 +113,6 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == Constant.REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY) { if (resultCode == Activity.RESULT_OK) { - if (data != null) { data.putExtra("modification", "updateAndViewCard") data.putExtra("updateDelay", 0) @@ -178,23 +158,24 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card LOG.d(TAG, "UID: $sUID") } - if (lastReadSuccess) { + if (lastReadSuccess) isoDep.timeout = 1000 - } else { + else isoDep.timeout = 65000 - } - //lastTag = tag; + verifyCardTask = VerifyCardTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, App.firmwaresStorage, this) - verifyCardTask!!.start() + verifyCardTask?.start() } catch (e: Exception) { e.printStackTrace() } } override fun onReadStart(cardProtocol: CardProtocol) { - progressBar!!.post { - progressBar!!.visibility = View.VISIBLE - progressBar!!.progress = 5 + rlProgressBar?.post { rlProgressBar.visibility = View.VISIBLE } + + progressBar?.post { + progressBar?.visibility = View.VISIBLE + progressBar?.progress = 5 } } @@ -202,37 +183,42 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card verifyCardTask = null if (cardProtocol != null) { if (cardProtocol.error == null) { - progressBar!!.post { - progressBar!!.progress = 100 - progressBar!!.progressTintList = ColorStateList.valueOf(Color.GREEN) -// val intent = Intent(this@EmptyWalletActivity, VerifyCardActivity::class.java) -// intent.putExtra("UID", cardProtocol.card.uid) -// intent.putExtra("Card", cardProtocol.card.asBundle) -// startActivityForResult(intent, REQUEST_CODE_VERIFY_CARD) - //addCard(cardProtocol.getCard()); + 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 { + progressBar?.post { lastReadSuccess = false if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) { - if (!NoExtendedLengthSupportDialog.allReadyShowed) { + if (!NoExtendedLengthSupportDialog.allReadyShowed) NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG) - } - } else { + } else Toast.makeText(this@EmptyWalletActivity, R.string.try_to_scan_again, Toast.LENGTH_LONG).show() - } - progressBar!!.progress = 100 - progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED) + + progressBar?.progress = 100 + progressBar?.progressTintList = ColorStateList.valueOf(Color.RED) } } } - progressBar!!.postDelayed({ + rlProgressBar?.postDelayed({ try { - progressBar!!.progress = 0 - progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY) - progressBar!!.visibility = View.INVISIBLE + 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() } @@ -240,16 +226,25 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card } override fun onReadProgress(protocol: CardProtocol, progress: Int) { - progressBar!!.post { progressBar!!.progress = progress } + progressBar?.post { progressBar!!.progress = progress } } override fun onReadCancel() { verifyCardTask = null - progressBar!!.postDelayed({ + + rlProgressBar?.postDelayed({ try { - progressBar!!.progress = 0 - progressBar!!.progressTintList = ColorStateList.valueOf(Color.DKGRAY) - progressBar!!.visibility = View.INVISIBLE + 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() } diff --git a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt index 449d9d26c0..4474b04951 100644 --- a/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt +++ b/app/src/main/java/com/tangem/presentation/fragment/LoadedWallet.kt @@ -457,8 +457,7 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback } override fun onReadStart(cardProtocol: CardProtocol) { - if (rlProgressBar != null) - rlProgressBar.post { rlProgressBar.visibility = View.VISIBLE } + rlProgressBar?.post { rlProgressBar.visibility = View.VISIBLE } } override fun onReadProgress(protocol: CardProtocol, progress: Int) { @@ -714,7 +713,7 @@ class LoadedWallet : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback Blockchain.BitcoinCash -> "bitcoin-cash" Blockchain.Litecoin -> "litecoin" Blockchain.Rootstock -> "bitcoin" - Blockchain.RootstockToken ->"bitcoin" + Blockchain.RootstockToken -> "bitcoin" else -> { throw Exception("Can''t get rate for blockchain " + ctx.blockchainName) } diff --git a/app/src/main/res/layout/activity_empty_wallet.xml b/app/src/main/res/layout/activity_empty_wallet.xml index 5505168234..eab69d393c 100644 --- a/app/src/main/res/layout/activity_empty_wallet.xml +++ b/app/src/main/res/layout/activity_empty_wallet.xml @@ -55,7 +55,7 @@ app:layout_constraintTop_toBottomOf="@+id/textView6" /> + app:layout_constraintTop_toBottomOf="@+id/btnDetails"> - - - - - - + app:layout_constraintTop_toBottomOf="@+id/guideline" + android:baselineAligned="false">