Updated on 2026-08-14
This commit is contained in:
parent
c13348a018
commit
09ef09c8b2
56 changed files with 1443 additions and 1617 deletions
|
|
@ -26,75 +26,75 @@ object Constant {
|
|||
|
||||
const val INTENT_TYPE_TEXT_PLAIN = "text/plain"
|
||||
|
||||
// LoadedWalletFragment, VerifyCard
|
||||
const val REQUEST_CODE_SEND_TRANSACTION = 1
|
||||
const val REQUEST_CODE_PURGE = 2
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3
|
||||
const val REQUEST_CODE_VERIFY_CARD = 4
|
||||
const val REQUEST_CODE_ENTER_NEW_PIN = 5
|
||||
const val REQUEST_CODE_ENTER_NEW_PIN2 = 6
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7
|
||||
const val REQUEST_CODE_SWAP_PIN = 8
|
||||
const val REQUEST_CODE_RECEIVE_TRANSACTION = 9
|
||||
// LoadedWalletFragment, VerifyCardFragment
|
||||
const val REQUEST_CODE_SEND_TRANSACTION = "REQUEST_CODE_SEND_TRANSACTION"
|
||||
const val REQUEST_CODE_PURGE = "REQUEST_CODE_PURGE"
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = "REQUEST_CODE_REQUEST_PIN2_FOR_PURGE"
|
||||
const val REQUEST_CODE_VERIFY_CARD = "REQUEST_CODE_VERIFY_CARD"
|
||||
const val REQUEST_CODE_ENTER_NEW_PIN = "REQUEST_CODE_ENTER_NEW_PIN"
|
||||
const val REQUEST_CODE_ENTER_NEW_PIN2 = "REQUEST_CODE_ENTER_NEW_PIN2"
|
||||
const val REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = "REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN"
|
||||
const val REQUEST_CODE_SWAP_PIN = "REQUEST_CODE_SWAP_PIN"
|
||||
const val REQUEST_CODE_RECEIVE_TRANSACTION = "REQUEST_CODE_RECEIVE_TRANSACTION"
|
||||
|
||||
// MainActivity
|
||||
const val REQUEST_CODE_SHOW_CARD_ACTIVITY = 1
|
||||
const val REQUEST_CODE_ENTER_PIN_ACTIVITY = 2
|
||||
const val REQUEST_CODE_SEND_EMAIL = 3
|
||||
// MainFragment
|
||||
const val REQUEST_CODE_SHOW_CARD_ACTIVITY = "REQUEST_CODE_SHOW_CARD_ACTIVITY"
|
||||
const val REQUEST_CODE_ENTER_PIN_ACTIVITY = "REQUEST_CODE_ENTER_PIN_ACTIVITY"
|
||||
const val REQUEST_CODE_SEND_EMAIL = "REQUEST_CODE_SEND_EMAIL"
|
||||
const val REQUEST_CODE_REQUEST_CAMERA_PERMISSIONS = 3
|
||||
|
||||
const val EXTRA_LAST_DISCOVERED_TAG = "extra_last_tag"
|
||||
const val EXTRA_PIN2 = "PIN2"
|
||||
|
||||
// LogoActivity
|
||||
// LogoFragment
|
||||
const val EXTRA_AUTO_HIDE = "extra_auto_hide"
|
||||
const val MILLIS_AUTO_HIDE = 1000
|
||||
|
||||
// PinRequestActivity
|
||||
// PinRequestFragment
|
||||
|
||||
const val KEY_ALIAS = "pinKey"
|
||||
const val KEYSTORE = "AndroidKeyStore"
|
||||
|
||||
// QrScanActivity
|
||||
// QrScanFragment
|
||||
const val EXTRA_QR_CODE = "QRCode"
|
||||
|
||||
// PinSwapActivity
|
||||
// PinSwapFragment
|
||||
const val EXTRA_CONFIRM_PIN = "confirmPIN"
|
||||
const val EXTRA_CONFIRM_PIN_2 = "confirmPIN2"
|
||||
const val EXTRA_NEW_PIN = "newPIN"
|
||||
const val EXTRA_NEW_PIN_2 = "newPIN2"
|
||||
|
||||
// CreateNewWalletActivity
|
||||
// CreateNewWalletFragment
|
||||
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
|
||||
// EmptyWalletFragment
|
||||
const val REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY = "REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY"
|
||||
const val REQUEST_CODE_REQUEST_PIN2 = "REQUEST_CODE_REQUEST_PIN2"
|
||||
|
||||
// ConfirmTransactionActivity
|
||||
const val REQUEST_CODE_SIGN_TRANSACTION = 1
|
||||
const val REQUEST_CODE_REQUEST_PIN2_ = 2
|
||||
// ConfirmTransactionFragment
|
||||
const val REQUEST_CODE_SIGN_TRANSACTION = "REQUEST_CODE_SIGN_TRANSACTION"
|
||||
const val REQUEST_CODE_REQUEST_PIN2_ = "REQUEST_CODE_REQUEST_PIN2_"
|
||||
|
||||
// SendTransactionActivity
|
||||
// SendTransactionFragment
|
||||
const val EXTRA_TX: String = "TX"
|
||||
|
||||
// SignTransactionActivity
|
||||
// SignTransactionFragment
|
||||
const val EXTRA_AMOUNT = "Amount"
|
||||
const val EXTRA_AMOUNT_CURRENCY = "AmountCurrency"
|
||||
const val EXTRA_FEE = "Fee"
|
||||
const val EXTRA_FEE_CURRENCY = "FeeCurrency"
|
||||
const val EXTRA_FEE_INCLUDED = "FeeIncluded"
|
||||
const val EXTRA_TARGET_ADDRESS = "TargetAddress"
|
||||
const val REQUEST_CODE_SEND_TRANSACTION_ = 1
|
||||
const val REQUEST_CODE_SEND_TRANSACTION_ = "REQUEST_CODE_SEND_TRANSACTION_"
|
||||
const val RESULT_INVALID_PIN_ = Activity.RESULT_FIRST_USER
|
||||
|
||||
// PrepareTransactionActivity
|
||||
const val REQUEST_CODE_SCAN_QR = 1
|
||||
const val REQUEST_CODE_SEND_TRANSACTION__ = 2
|
||||
// PrepareTransactionFragment
|
||||
const val REQUEST_CODE_SCAN_QR = "REQUEST_CODE_SCAN_QR"
|
||||
const val REQUEST_CODE_SEND_TRANSACTION__ = "REQUEST_CODE_SEND_TRANSACTION__"
|
||||
|
||||
// PrepareCryptonitOtherApiWithdrawalActivity
|
||||
const val REQUEST_CODE_SCAN_QR_KEY = 1
|
||||
const val REQUEST_CODE_SCAN_QR_SECRET = 2
|
||||
const val REQUEST_CODE_SCAN_QR_USER_ID = 3
|
||||
// PrepareCryptonitOtherApiWithdrawalFragment
|
||||
const val REQUEST_CODE_SCAN_QR_KEY = "REQUEST_CODE_SCAN_QR_KEY"
|
||||
const val REQUEST_CODE_SCAN_QR_SECRET = "REQUEST_CODE_SCAN_QR_SECRET"
|
||||
const val REQUEST_CODE_SCAN_QR_USER_ID = "REQUEST_CODE_SCAN_QR_USER_ID"
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package com.tangem.data.fingerprint;
|
|||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.tangem.ui.activity.PinSaveActivity;
|
||||
import com.tangem.ui.fragment.pin.PinSaveFragment;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
|
@ -11,9 +11,9 @@ import java.lang.ref.WeakReference;
|
|||
import javax.crypto.Cipher;
|
||||
|
||||
public class ConfirmWithFingerprintTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private WeakReference<PinSaveActivity> reference;
|
||||
private WeakReference<PinSaveFragment> reference;
|
||||
|
||||
public ConfirmWithFingerprintTask(PinSaveActivity context) {
|
||||
public ConfirmWithFingerprintTask(PinSaveFragment context) {
|
||||
reference = new WeakReference<>(context);
|
||||
|
||||
reference.get().setFingerprintHelper(new FingerprintHelper(reference.get()));
|
||||
|
|
@ -21,40 +21,40 @@ public class ConfirmWithFingerprintTask extends AsyncTask<Void, Void, Boolean> {
|
|||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
PinSaveActivity pinSaveActivity = reference.get();
|
||||
PinSaveFragment pinSaveFragment = reference.get();
|
||||
|
||||
if (!pinSaveActivity.getKeyStore())
|
||||
if (!pinSaveFragment.getKeyStore())
|
||||
return false;
|
||||
|
||||
if (!pinSaveActivity.createNewKey(false))
|
||||
if (!pinSaveFragment.createNewKey(false))
|
||||
return false;
|
||||
|
||||
if (!pinSaveActivity.getCipher())
|
||||
if (!pinSaveFragment.getCipher())
|
||||
return false;
|
||||
|
||||
return pinSaveActivity.initCipher(Cipher.ENCRYPT_MODE) && pinSaveActivity.initCryptObject();
|
||||
return pinSaveFragment.initCipher(Cipher.ENCRYPT_MODE) && pinSaveFragment.initCryptObject();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
PinSaveActivity pinSaveActivity = reference.get();
|
||||
PinSaveFragment pinSaveFragment = reference.get();
|
||||
|
||||
onCancelled();
|
||||
|
||||
if (!success) {
|
||||
Toast.makeText(pinSaveActivity, R.string.pin_save_fail, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(pinSaveFragment.getContext(), R.string.pin_save_fail, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
pinSaveActivity.getFingerprintHelper().startAuth(pinSaveActivity.getFingerprintManager(), pinSaveActivity.getCryptoObject());
|
||||
pinSaveFragment.getFingerprintHelper().startAuth(pinSaveFragment.getFingerprintManager(), pinSaveFragment.getCryptoObject());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
PinSaveActivity pinSaveActivity = reference.get();
|
||||
PinSaveFragment pinSaveFragment = reference.get();
|
||||
|
||||
if (pinSaveActivity.getDFingerPrintConfirmation() != null) {
|
||||
pinSaveActivity.getDFingerPrintConfirmation().cancel();
|
||||
if (pinSaveFragment.getDFingerPrintConfirmation() != null) {
|
||||
pinSaveFragment.getDFingerPrintConfirmation().cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import android.security.keystore.KeyProperties;
|
|||
|
||||
import com.tangem.Constant;
|
||||
import com.tangem.card_android.android.data.PINStorage;
|
||||
import com.tangem.ui.activity.PinRequestActivity;
|
||||
import com.tangem.ui.fragment.pin.PinRequestFragment;
|
||||
import com.tangem.util.LOG;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -29,7 +29,7 @@ import javax.crypto.spec.IvParameterSpec;
|
|||
public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
|
||||
public static final String TAG = StartFingerprintReaderTask.class.getSimpleName();
|
||||
|
||||
private WeakReference<PinRequestActivity> reference;
|
||||
private WeakReference<PinRequestFragment> reference;
|
||||
|
||||
private KeyStore keyStore;
|
||||
private Cipher cipher;
|
||||
|
|
@ -39,13 +39,13 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
|
|||
FingerprintManager fingerprintManager;
|
||||
FingerprintHelper fingerprintHelper;
|
||||
|
||||
PinRequestActivity activity;
|
||||
PinRequestFragment fragment;
|
||||
|
||||
public StartFingerprintReaderTask(PinRequestActivity activity, FingerprintManager fingerprintManager, FingerprintHelper fingerprintHelper) {
|
||||
reference = new WeakReference<>(activity);
|
||||
public StartFingerprintReaderTask(PinRequestFragment fragment, FingerprintManager fingerprintManager, FingerprintHelper fingerprintHelper) {
|
||||
reference = new WeakReference<>(fragment);
|
||||
this.fingerprintManager = fingerprintManager;
|
||||
this.fingerprintHelper = fingerprintHelper;
|
||||
this.activity = activity;
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -80,9 +80,9 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
|
|||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
PinRequestActivity pinRequestActivity = reference.get();
|
||||
PinRequestFragment fragment = reference.get();
|
||||
|
||||
pinRequestActivity.setStartFingerprintReaderTask(null);
|
||||
fragment.setStartFingerprintReaderTask(null);
|
||||
}
|
||||
|
||||
private boolean getKeyStore() {
|
||||
|
|
@ -143,7 +143,7 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
|
|||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
private boolean initCipher(int mode) {
|
||||
PinRequestActivity pinRequestActivity = reference.get();
|
||||
PinRequestFragment fragment = reference.get();
|
||||
|
||||
LOG.i(TAG, "Initializing cipher...");
|
||||
try {
|
||||
|
|
@ -154,9 +154,13 @@ public class StartFingerprintReaderTask extends AsyncTask<Void, Void, Boolean> {
|
|||
cipher.init(mode, keyspec);
|
||||
} else {
|
||||
byte[] iv = null;
|
||||
if (pinRequestActivity.getMode() == PinRequestActivity.Mode.RequestPIN || activity.getMode() == PinRequestActivity.Mode.RequestNewPIN || activity.getMode() == PinRequestActivity.Mode.ConfirmNewPIN) {
|
||||
if (fragment.getMode() == PinRequestFragment.Mode.RequestPIN ||
|
||||
fragment.getMode() == PinRequestFragment.Mode.RequestNewPIN ||
|
||||
fragment.getMode() == PinRequestFragment.Mode.ConfirmNewPIN) {
|
||||
iv = PINStorage.loadEncryptedIV();
|
||||
} else if (activity.getMode() == PinRequestActivity.Mode.RequestPIN2 || activity.getMode() == PinRequestActivity.Mode.RequestNewPIN2 || activity.getMode() == PinRequestActivity.Mode.ConfirmNewPIN2) {
|
||||
} else if (fragment.getMode() == PinRequestFragment.Mode.RequestPIN2 ||
|
||||
fragment.getMode() == PinRequestFragment.Mode.RequestNewPIN2 ||
|
||||
fragment.getMode() == PinRequestFragment.Mode.ConfirmNewPIN2) {
|
||||
iv = PINStorage.loadEncryptedIV2();
|
||||
}
|
||||
IvParameterSpec ivspec = new IvParameterSpec(iv);
|
||||
|
|
|
|||
|
|
@ -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,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)
|
||||
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()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,17 +10,17 @@ import android.view.View;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.tangem.card_common.util.Log;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
/**
|
||||
* Created by dvol on 06.03.2018.
|
||||
*/
|
||||
|
|
@ -78,7 +78,7 @@ public class WaitSecurityDelayDialog extends DialogFragment {
|
|||
super.onCancel(dialog);
|
||||
}
|
||||
|
||||
public static void onReadBeforeRequest(final AppCompatActivity activity, final int timeout) {
|
||||
public static void onReadBeforeRequest(final FragmentActivity activity, final int timeout) {
|
||||
activity.runOnUiThread(() -> {
|
||||
if (timerToShowDelayDialog != null || timeout < delayBeforeShowDialog + minRemainingDelayToShowDialog)
|
||||
return;
|
||||
|
|
@ -104,7 +104,7 @@ public class WaitSecurityDelayDialog extends DialogFragment {
|
|||
});
|
||||
}
|
||||
|
||||
public static void onReadWait(final AppCompatActivity activity, final int msec) {
|
||||
public static void onReadWait(final FragmentActivity activity, final int msec) {
|
||||
Log.e(TAG, "onReadWait callback(" + msec + ")");
|
||||
activity.runOnUiThread(() -> {
|
||||
Log.e(TAG, "onReadWait on ui thread(" + msec + ")");
|
||||
|
|
|
|||
|
|
@ -1,45 +1,32 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment
|
||||
|
||||
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.TangemContext
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_logo.*
|
||||
import javax.inject.Inject
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_logo.*
|
||||
|
||||
class LogoActivity : AppCompatActivity() {
|
||||
class LogoFragment : BaseFragment() {
|
||||
companion object {
|
||||
fun callingIntent(context: Context, autoHide: Boolean): Intent {
|
||||
val intent = Intent(context, LogoActivity::class.java)
|
||||
val intent = Intent(context, LogoFragment::class.java)
|
||||
intent.putExtra(Constant.EXTRA_AUTO_HIDE, autoHide)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
override val layoutId = R.layout.fragment_logo
|
||||
|
||||
private val hideRunnable = Runnable { this.hide() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_logo)
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
ivLogo.setOnClickListener { hide() }
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
|
||||
// set beta version name
|
||||
if (BuildConfig.DEBUG)
|
||||
tvAppVersion.text = String.format(getString(R.string.version_name_debug), BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
|
||||
|
|
@ -57,21 +44,20 @@ class LogoActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
if (intent.getBooleanExtra(Constant.EXTRA_AUTO_HIDE, true))
|
||||
if (arguments?.getBoolean(Constant.EXTRA_AUTO_HIDE, true) != false)
|
||||
ivLogo.postDelayed(hideRunnable, Constant.MILLIS_AUTO_HIDE.toLong())
|
||||
}
|
||||
|
||||
private fun hide() {
|
||||
when (BuildConfig.FLAVOR) {
|
||||
Constant.FLAVOR_TANGEM_CARDANO -> {
|
||||
navigator.showPrepareTransaction(this, TangemContext())
|
||||
navigateToDestination(R.id.action_logoFragment_to_prepareTransactionFragment,
|
||||
Bundle().apply { TangemContext().saveToBundle(this) })
|
||||
}
|
||||
else -> {
|
||||
navigator.showMain(this)
|
||||
navigateToDestination(R.id.action_logoFragment_to_main)
|
||||
}
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package com.tangem.ui.fragment
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.nfc.tech.IsoDep
|
||||
|
|
@ -10,14 +9,12 @@ import android.view.*
|
|||
import android.widget.PopupMenu
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
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
|
||||
|
|
@ -28,11 +25,11 @@ import com.tangem.card_common.reader.CardProtocol
|
|||
import com.tangem.card_common.tasks.CustomReadCardTask
|
||||
import com.tangem.card_common.tasks.ReadCardInfoTask
|
||||
import com.tangem.data.Logger
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.activity.PinRequestActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.fragment.pin.PinRequestFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.util.CommonUtil
|
||||
import com.tangem.util.LOG
|
||||
import com.tangem.util.UtilHelper
|
||||
|
|
@ -45,30 +42,26 @@ import kotlinx.android.synthetic.main.main_fragment.*
|
|||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, androidx.appcompat.widget.PopupMenu.OnMenuItemClickListener, PopupMenu.OnMenuItemClickListener {
|
||||
class MainFragment : BaseFragment(), NavigationResultListener, NfcAdapter.ReaderCallback,
|
||||
CardProtocol.Notifications, androidx.appcompat.widget.PopupMenu.OnMenuItemClickListener,
|
||||
PopupMenu.OnMenuItemClickListener {
|
||||
|
||||
companion object {
|
||||
fun newInstance() = MainFragment()
|
||||
val TAG: String = MainFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
override val layoutId = R.layout.main_fragment
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var nfcDeviceAntenna: NfcDeviceAntennaLocation
|
||||
private var unsuccessReadCount = 0
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private var task: CustomReadCardTask? = null
|
||||
private var lastTag: Tag? = null
|
||||
private var zipFile: File? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
nfcManager = NfcManager(activity!!, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
setHasOptionsMenu(true)
|
||||
return inflater.inflate(R.layout.main_fragment, container, false)
|
||||
return super.onCreateView(inflater, container, savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
@ -95,7 +88,7 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
// show snackbar about new version app
|
||||
viewModel.getVersionName().observe(this, Observer { text ->
|
||||
(activity as MainActivity).toastHelper.showSnackbarUpdateVersion(context!!, cl, text)
|
||||
(activity as MainActivity).toastHelper.showSnackbarUpdateVersion(requireContext(), cl, text)
|
||||
})
|
||||
|
||||
val intent = activity?.intent
|
||||
|
|
@ -131,11 +124,12 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
lastTag = tag
|
||||
|
||||
task = ReadCardInfoTask(NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, this)
|
||||
task = ReadCardInfoTask(NfcReader((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, this)
|
||||
task?.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
nfcManager.notifyReadResult(false)
|
||||
(activity as MainActivity).nfcManager.notifyReadResult(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +145,7 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
task = null
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
nfcManager.notifyReadResult(true)
|
||||
(activity as MainActivity).nfcManager.notifyReadResult(true)
|
||||
rlProgressBar?.post {
|
||||
rlProgressBar?.visibility = View.GONE
|
||||
|
||||
|
|
@ -179,10 +173,18 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// ctx.saveToBundle(bundle)
|
||||
// (activity as MainActivity).navController.navigate(R.id.loadedWallet, bundle)
|
||||
|
||||
(activity as MainActivity).navigator.showLoadedWallet(activity!!, it, ctx)
|
||||
val bundle = Bundle()
|
||||
bundle.putParcelable(Constant.EXTRA_LAST_DISCOVERED_TAG, lastTag)
|
||||
ctx.saveToBundle(bundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_SHOW_CARD_ACTIVITY,
|
||||
R.id.action_main_to_loadedWalletFragment, bundle)
|
||||
|
||||
}
|
||||
}
|
||||
card.status == TangemCard.Status.Empty -> (activity as MainActivity).navigator.showEmptyWallet(activity!!, ctx)
|
||||
card.status == TangemCard.Status.Empty -> {
|
||||
val bundle = Bundle().apply { ctx.saveToBundle(this) }
|
||||
navigateToDestination(R.id.action_main_to_emptyWalletFragment, bundle)
|
||||
}
|
||||
card.status == TangemCard.Status.Purged -> Toast.makeText(context, R.string.erased_wallet, Toast.LENGTH_SHORT).show()
|
||||
card.status == TangemCard.Status.NotPersonalized -> Toast.makeText(context, R.string.not_personalized, Toast.LENGTH_SHORT).show()
|
||||
else -> {
|
||||
|
|
@ -203,43 +205,33 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
Toast.makeText(context, R.string.try_to_scan_again, Toast.LENGTH_SHORT).show()
|
||||
unsuccessReadCount++
|
||||
|
||||
if (cardProtocol.error is CardProtocol.TangemException_InvalidPIN)
|
||||
(activity as MainActivity).navigator.showPinRequest(activity!!, PinRequestActivity.Mode.RequestPIN.toString())
|
||||
else {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_InvalidPIN) {
|
||||
val data = Bundle().apply { putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN.toString()) }
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_PIN_ACTIVITY,
|
||||
R.id.action_main_to_pinRequestFragment, data)
|
||||
} else {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported)
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed)
|
||||
NoExtendedLengthSupportDialog().show(activity!!.supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
|
||||
lastTag = null
|
||||
ReadCardInfoTask.resetLastReadInfo()
|
||||
nfcManager.notifyReadResult(false)
|
||||
(activity as MainActivity).nfcManager.notifyReadResult(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rlProgressBar.postDelayed({
|
||||
try {
|
||||
rlProgressBar.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
rlProgressBar?.postDelayed({ rlProgressBar?.visibility = View.GONE }, 500)
|
||||
}
|
||||
|
||||
override fun onReadCancel() {
|
||||
task = null
|
||||
ReadCardInfoTask.resetLastReadInfo()
|
||||
rlProgressBar.postDelayed({
|
||||
try {
|
||||
rlProgressBar.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}, 500)
|
||||
rlProgressBar?.postDelayed({ rlProgressBar?.visibility = View.GONE }, 500)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_SEND_EMAIL -> {
|
||||
if (zipFile != null) {
|
||||
|
|
@ -254,7 +246,6 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
ReadCardInfoTask.resetLastReadInfo()
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
|
@ -286,26 +277,25 @@ class MainFragment : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
return true
|
||||
}
|
||||
R.id.managePIN -> {
|
||||
(activity as MainActivity).navigator.showPinSave(activity!!, false)
|
||||
// (activity as MainActivity).navController.navigate(R.id.pinSaveActivity)
|
||||
navigateToDestination(R.id.action_main_to_pinSaveFragment,
|
||||
bundleOf(Constant.EXTRA_PIN2 to false))
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.managePIN2 -> {
|
||||
(activity as MainActivity).navigator.showPinSave(activity!!, true)
|
||||
// (activity as MainActivity).navController.navigate(R.id.pinSaveActivity)
|
||||
navigateToDestination(R.id.action_main_to_pinSaveFragment,
|
||||
bundleOf(Constant.EXTRA_PIN2 to true))
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.settings -> {
|
||||
(activity as MainActivity).navigator.showSettings(activity!!)
|
||||
// (activity as MainActivity).navController.navigate(R.id.settingsActivity)
|
||||
navigateToDestination(R.id.action_main_to_settingsFragment)
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.about -> {
|
||||
(activity as MainActivity).navigator.showLogo(activity!!, false)
|
||||
// (activity as MainActivity).navController.navigate(R.id.logoActivity)
|
||||
val bundle = Bundle().apply { putBoolean(Constant.EXTRA_AUTO_HIDE, false) }
|
||||
navigateToDestination(R.id.action_main_to_logoFragment, bundle)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment
|
||||
|
||||
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
|
||||
|
|
@ -12,36 +11,33 @@ import android.nfc.tech.IsoDep
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.os.bundleOf
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.wallet.TangemContext
|
||||
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.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.activity.MainActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialogNew
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_purge.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_purge.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import javax.inject.Inject
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
|
||||
class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
class PurgeFragment : BaseFragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = PurgeActivity::class.java.simpleName
|
||||
val TAG: String = PurgeFragment::class.java.simpleName
|
||||
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, PurgeActivity::class.java)
|
||||
val intent = Intent(context, PurgeFragment::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
|
|
@ -52,7 +48,8 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
@Inject
|
||||
internal lateinit var waitSecurityDelayDialogNew: WaitSecurityDelayDialogNew
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fragment_purge
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private lateinit var nfcDeviceAntenna: NfcDeviceAntennaLocation
|
||||
|
|
@ -61,19 +58,14 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_purge)
|
||||
ctx = TangemContext.loadFromBundle(context, arguments)
|
||||
}
|
||||
|
||||
App.navigatorComponent.inject(this)
|
||||
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
|
||||
nfcManager = NfcManager(this, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
|
||||
ctx = TangemContext.loadFromBundle(this, intent.extras)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// init NFC Antenna
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(this, ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(context!!, ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna.init()
|
||||
|
||||
tvCardID.text = ctx.card.cidDescription
|
||||
|
|
@ -81,7 +73,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
progressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
|
||||
public override fun onStop() {
|
||||
override fun onStop() {
|
||||
purgeTask?.cancel(true)
|
||||
super.onStop()
|
||||
}
|
||||
|
|
@ -94,10 +86,11 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
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 = PurgeTask(ctx.card, NfcReader((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, this)
|
||||
purgeTask?.start()
|
||||
} else {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -105,7 +98,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
WaitSecurityDelayDialog.onReadWait(activity, msec)
|
||||
|
||||
// val readWait = ReadWait()
|
||||
// readWait.msec = msec
|
||||
|
|
@ -113,7 +106,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(activity, timeout)
|
||||
|
||||
// if (!waitSecurityDelayDialogNew.isAdded)
|
||||
// waitSecurityDelayDialogNew.show(supportFragmentManager, WaitSecurityDelayDialogNew.TAG)
|
||||
|
|
@ -125,7 +118,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(activity)
|
||||
|
||||
// val readAfterRequest = ReadAfterRequest()
|
||||
// EventBus.getDefault().post(readAfterRequest)
|
||||
|
|
@ -145,20 +138,18 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
|
||||
if (cardProtocol != null) {
|
||||
if (cardProtocol.error == null) {
|
||||
rlProgressBar.post { rlProgressBar.visibility = View.GONE }
|
||||
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)
|
||||
val data = Bundle()
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
|
||||
EventBus.getDefault().post(DeletingWalletFinish())
|
||||
|
||||
finish()
|
||||
// EventBus.getDefault().post(DeletingWalletFinish())
|
||||
navigateToDestination(R.id.action_purgeFragment_to_mainFragment)
|
||||
}
|
||||
} else {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_InvalidPIN) {
|
||||
|
|
@ -172,12 +163,13 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
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.cannot_erase_wallet))
|
||||
setResult(RESULT_INVALID_PIN, intent)
|
||||
finish()
|
||||
val data = bundleOf(
|
||||
EXTRA_TANGEM_CARD_UID to cardProtocol.card.uid,
|
||||
EXTRA_TANGEM_CARD to cardProtocol.card.asBundle,
|
||||
Constant.EXTRA_MESSAGE to getString(R.string.cannot_erase_wallet)
|
||||
)
|
||||
navigateBackWithResult(RESULT_INVALID_PIN, data)
|
||||
return@postDelayed
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -186,9 +178,9 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
progressBar?.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed)
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
NoExtendedLengthSupportDialog().show(activity!!.supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
} else
|
||||
Toast.makeText(baseContext, R.string.try_to_scan_again, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, R.string.try_to_scan_again, Toast.LENGTH_LONG).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
|
|
@ -199,7 +191,7 @@ class PurgeActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoc
|
|||
|
||||
rlProgressBar?.postDelayed({
|
||||
try {
|
||||
rlProgressBar.visibility = View.GONE
|
||||
rlProgressBar?.visibility = View.GONE
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
|
|
@ -6,36 +6,45 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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 {
|
||||
class QrScanFragment : BaseFragment(), ZXingScannerView.ResultHandler {
|
||||
companion object {
|
||||
fun callingIntent(context: Context): Intent {
|
||||
return Intent(context, QrScanActivity::class.java)
|
||||
return Intent(context, QrScanFragment::class.java)
|
||||
}
|
||||
}
|
||||
|
||||
override val layoutId = 0
|
||||
|
||||
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()
|
||||
if (ActivityCompat.checkSelfPermission(context!!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
|
||||
ActivityCompat.requestPermissions(activity!!, arrayOf(Manifest.permission.CAMERA), 1)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
scannerView = ZXingScannerView(activity)
|
||||
return scannerView
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
scannerView?.stopCamera()
|
||||
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
scannerView?.setResultHandler(this)
|
||||
scannerView?.startCamera()
|
||||
}
|
||||
|
||||
|
|
@ -43,30 +52,19 @@ class QrScanActivity : AppCompatActivity(), ZXingScannerView.ResultHandler {
|
|||
when (requestCode) {
|
||||
1 -> {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)
|
||||
runScanner()
|
||||
|
||||
else {
|
||||
setResult(Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
navigateBackWithResult(Activity.RESULT_CANCELED)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun handleResult(result: Result) {
|
||||
val data = Intent()
|
||||
data.putExtra(Constant.EXTRA_QR_CODE, result.text)
|
||||
setResult(Activity.RESULT_OK, data)
|
||||
finish()
|
||||
}
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_QR_CODE, result.text)
|
||||
|
||||
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()
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,43 +1,37 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment
|
||||
|
||||
import android.content.Intent
|
||||
import android.app.Activity
|
||||
import android.nfc.NfcAdapter
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.KeyEvent
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.wallet.CoinEngine
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.card_common.util.Util
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.event.TransactionFinishWithError
|
||||
import com.tangem.ui.event.TransactionFinishWithSuccess
|
||||
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.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 {
|
||||
class SendTransactionFragment : BaseFragment(), NfcAdapter.ReaderCallback {
|
||||
|
||||
override val layoutId = R.layout.fragment_send_transaction
|
||||
|
||||
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)
|
||||
ctx = TangemContext.loadFromBundle(context, arguments)
|
||||
tx = arguments?.getByteArray(Constant.EXTRA_TX)
|
||||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
|
|
@ -55,26 +49,24 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
}
|
||||
|
||||
override fun allowAdvance(): Boolean {
|
||||
return UtilHelper.isOnline(this@SendTransactionActivity)
|
||||
return UtilHelper.isOnline(requireContext())
|
||||
}
|
||||
},
|
||||
tx
|
||||
)
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_BACK -> {
|
||||
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_LONG).show()
|
||||
return true
|
||||
val callback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
Toast.makeText(context, R.string.please_wait, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
}
|
||||
return super.onKeyDown(keyCode, event)
|
||||
requireActivity().onBackPressedDispatcher.addCallback(this, callback)
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -85,10 +77,9 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
transactionFinishWithSuccess.message = getString(R.string.transaction_has_been_successfully_signed)
|
||||
EventBus.getDefault().post(transactionFinishWithSuccess)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, getString(R.string.transaction_has_been_successfully_signed))
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MESSAGE, getString(R.string.transaction_has_been_successfully_signed))
|
||||
navigateBackWithResult(Activity.RESULT_OK, data, R.id.loadedWalletFragment)
|
||||
}
|
||||
|
||||
private fun finishWithError(message: String) {
|
||||
|
|
@ -96,10 +87,9 @@ class SendTransactionActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
|||
transactionFinishWithError.message = String.format(getString(R.string.try_again_failed_to_send_transaction), message)
|
||||
EventBus.getDefault().post(transactionFinishWithError)
|
||||
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, String.format(getString(R.string.try_again_failed_to_send_transaction), message))
|
||||
setResult(RESULT_CANCELED, intent)
|
||||
finish()
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MESSAGE, String.format(getString(R.string.try_again_failed_to_send_transaction), message))
|
||||
navigateBackWithResult(Activity.RESULT_CANCELED, data, R.id.loadedWalletFragment)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
package com.tangem.ui.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.fragment_settings.*
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
|
|
@ -22,4 +26,23 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initToolbar()
|
||||
}
|
||||
|
||||
private fun initToolbar() {
|
||||
toolbar?.setTitle(R.string.settings)
|
||||
toolbar?.setNavigationIcon(android.R.drawable.ic_menu_close_clear_cancel)
|
||||
(activity as AppCompatActivity).setSupportActionBar(toolbar)
|
||||
toolbar?.setNavigationOnClickListener {
|
||||
NavHostFragment.findNavController(this).popBackStack()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
(activity as AppCompatActivity).setSupportActionBar(toolbar)
|
||||
super.onDestroyView()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,43 +8,42 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.text.format.DateUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.PopupMenu
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.tangem.App
|
||||
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.card_common.reader.CardProtocol
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.ui.activity.PinRequestActivity
|
||||
import com.tangem.ui.activity.VerifyCardActivity
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.dialog.PINSwapWarningDialog
|
||||
import com.tangem.ui.event.DeletingWalletFinish
|
||||
import com.tangem.ui.fragment.pin.PinRequestFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fr_verify_card.*
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
||||
class VerifyCardFragment : BaseFragment(), NavigationResultListener, NfcAdapter.ReaderCallback {
|
||||
companion object {
|
||||
val TAG: String = VerifyCard::class.java.simpleName
|
||||
val TAG: String = VerifyCardFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fr_verify_card
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
|
||||
private var requestPIN2Count = 0
|
||||
|
|
@ -54,14 +53,16 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ctx = TangemContext.loadFromBundle(activity, activity?.intent?.extras)
|
||||
ctx = TangemContext.loadFromBundle(context, arguments)
|
||||
|
||||
nfcManager = NfcManager(activity!!, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fr_verify_card, container, false)
|
||||
val callback = object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
val data = prepareResultIntent()
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, getString(R.string.update))
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
requireActivity().onBackPressedDispatcher.addCallback(this, callback)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
@ -76,7 +77,7 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
btnOk.setOnClickListener {
|
||||
val data = prepareResultIntent()
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, getString(R.string.update))
|
||||
activity?.finish()
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,39 +97,44 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
activity?.finish()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_ENTER_NEW_PIN -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
if (data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN)) {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
newPIN = data.getStringExtra(Constant.EXTRA_NEW_PIN)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
if (data.containsKey(Constant.EXTRA_CONFIRM_PIN)) {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(bundle)
|
||||
newPIN = data.getString(Constant.EXTRA_NEW_PIN)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, bundle)
|
||||
} else {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN, data.getStringExtra(Constant.EXTRA_NEW_PIN))
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.ConfirmNewPIN.toString())
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN, data.getString(Constant.EXTRA_NEW_PIN))
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.ConfirmNewPIN.toString())
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, bundle)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Constant.REQUEST_CODE_ENTER_NEW_PIN2 -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
if (data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN_2)) {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
newPIN2 = data.getStringExtra(Constant.EXTRA_NEW_PIN_2)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
if (data.containsKey(Constant.EXTRA_CONFIRM_PIN_2)) {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(bundle)
|
||||
newPIN2 = data.getString(Constant.EXTRA_NEW_PIN_2)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, bundle)
|
||||
|
||||
} else {
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_NEW_PIN_2, data.getStringExtra(Constant.EXTRA_NEW_PIN_2))
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.ConfirmNewPIN2.toString())
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN2)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN_2, data.getString(Constant.EXTRA_NEW_PIN_2))
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.ConfirmNewPIN2.toString())
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN2,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, bundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -139,7 +145,13 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
if (newPIN2 == "") newPIN2 = App.pinStorage.piN2
|
||||
|
||||
val pinSwapWarningDialog = PINSwapWarningDialog()
|
||||
pinSwapWarningDialog.setOnRefreshPage { (activity as VerifyCardActivity).navigator.showPinSwap(context as Activity, newPIN, newPIN2) }
|
||||
pinSwapWarningDialog.setOnRefreshPage {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
navigateForResult(Constant.REQUEST_CODE_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinSwapFragment, bundle)
|
||||
}
|
||||
val bundle = Bundle()
|
||||
if (!CardProtocol.isDefaultPIN(newPIN) || !CardProtocol.isDefaultPIN2(newPIN2))
|
||||
bundle.putString(Constant.EXTRA_MESSAGE, getString(R.string.if_you_forget))
|
||||
|
|
@ -151,51 +163,56 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
|
||||
Constant.REQUEST_CODE_SWAP_PIN -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
ctx.saveToIntent(data)
|
||||
data?.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
} else
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
activity?.setResult(Activity.RESULT_OK, data)
|
||||
activity?.finish()
|
||||
val newData = Bundle()
|
||||
ctx.saveToBundle(newData)
|
||||
newData.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, newData)
|
||||
} else {
|
||||
data.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
} 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))
|
||||
if (data != null && data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
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())
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(bundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, bundle)
|
||||
return
|
||||
} else {
|
||||
if (data != null && data.extras!!.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getStringExtra(Constant.EXTRA_MESSAGE)
|
||||
if (data != null && data.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getString(Constant.EXTRA_MESSAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK)
|
||||
(activity as VerifyCardActivity).navigator.showPurge(context as Activity, ctx)
|
||||
|
||||
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))
|
||||
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE -> if (resultCode == Activity.RESULT_OK) {
|
||||
val bundle = Bundle().apply { ctx.saveToBundle(this) }
|
||||
navigateForResult(Constant.REQUEST_CODE_PURGE,
|
||||
R.id.action_verifyCard_to_purgeFragment, bundle)
|
||||
} else {
|
||||
if (data != null && data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
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())
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(bundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
return
|
||||
} else {
|
||||
if (data != null && data.extras!!.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getStringExtra(Constant.EXTRA_MESSAGE)
|
||||
if (data != null && data.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getString(Constant.EXTRA_MESSAGE)
|
||||
}
|
||||
}
|
||||
updateViews()
|
||||
|
|
@ -205,7 +222,7 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
|
||||
override fun onTagDiscovered(tag: Tag?) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag!!)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag!!)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -268,15 +285,15 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
else
|
||||
tvReusable.setText(R.string.one_off_banknote)
|
||||
|
||||
var s=""
|
||||
for(signingM in ctx.card!!.allowedSigningMethod) {
|
||||
s += if(signingM==ctx.card!!.signingMethod) {
|
||||
var s = ""
|
||||
for (signingM in ctx.card!!.allowedSigningMethod) {
|
||||
s += if (signingM == ctx.card!!.signingMethod) {
|
||||
", <b>${signingM.description}</b>"
|
||||
} else {
|
||||
", <small>${signingM.description}</small>"
|
||||
}
|
||||
}
|
||||
s=s.substring(2,s.length)
|
||||
s = s.substring(2, s.length)
|
||||
@Suppress("DEPRECATION")
|
||||
tvSigningMethod.text = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
Html.fromHtml(s, Html.FROM_HTML_MODE_LEGACY)
|
||||
|
|
@ -392,50 +409,55 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
|
||||
private fun doSetPin() {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestNewPIN.toString())
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestNewPIN.toString())
|
||||
newPIN = ""
|
||||
newPIN2 = ""
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN)
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
private fun doResetPin() {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(data)
|
||||
newPIN = PINStorage.getDefaultPIN()
|
||||
newPIN2 = ""
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
private fun doResetPin2() {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(data)
|
||||
newPIN = ""
|
||||
newPIN2 = PINStorage.getDefaultPIN2()
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
private fun doResetPins() {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(data)
|
||||
newPIN = PINStorage.getDefaultPIN()
|
||||
newPIN2 = PINStorage.getDefaultPIN2()
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
private fun doSetPin2() {
|
||||
requestPIN2Count = 0
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestNewPIN2.toString())
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestNewPIN2.toString())
|
||||
newPIN = ""
|
||||
newPIN2 = ""
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_ENTER_NEW_PIN2)
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN2,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
private fun doPurge() {
|
||||
|
|
@ -448,10 +470,11 @@ class VerifyCard : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback {
|
|||
return
|
||||
}
|
||||
|
||||
val intent = Intent(context, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE)
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(data)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE,
|
||||
R.id.action_verifyCard_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
fun prepareResultIntent(): Intent {
|
||||
|
|
@ -1,59 +1,40 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.additional
|
||||
|
||||
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 androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.CryptonitOtherApi
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_other_api_withdrawal.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_prepare_cryptonit_other_api_withdrawal.*
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
|
||||
class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
class PrepareCryptonitOtherApiWithdrawalFragment : BaseFragment(), NavigationResultListener,
|
||||
NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareCryptonitOtherApiWithdrawalActivity::class.java.simpleName
|
||||
val TAG: String = PrepareCryptonitOtherApiWithdrawalFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
override val layoutId = R.layout.fragment_prepare_cryptonit_other_api_withdrawal
|
||||
|
||||
private var cryptonit: CryptonitOtherApi? = null
|
||||
private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
|
||||
private val cryptonit: CryptonitOtherApi by lazy { CryptonitOtherApi(context) }
|
||||
|
||||
@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
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
tvKey.text = cryptonit.key
|
||||
tvUserID.text = cryptonit.userId
|
||||
tvSecret.text = cryptonit.secretDescription
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
|
|
@ -75,7 +56,7 @@ class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestCryptoWithdrawal(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
cryptonit.requestCryptoWithdrawal(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
|
@ -88,15 +69,27 @@ class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
// }
|
||||
|
||||
}
|
||||
ivCameraKey.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_KEY) }
|
||||
ivCameraKey.setOnClickListener {
|
||||
navigateForResult(
|
||||
Constant.REQUEST_CODE_SCAN_QR_KEY,
|
||||
R.id.action_prepareCryptonitOtherApiWithdrawalFragment_to_qrScanFragment)
|
||||
}
|
||||
|
||||
ivCameraSecret.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_SECRET) }
|
||||
ivCameraSecret.setOnClickListener {
|
||||
navigateForResult(
|
||||
Constant.REQUEST_CODE_SCAN_QR_SECRET,
|
||||
R.id.action_prepareCryptonitOtherApiWithdrawalFragment_to_qrScanFragment)
|
||||
}
|
||||
|
||||
ivCameraUserId.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR_USER_ID) }
|
||||
ivCameraUserId.setOnClickListener {
|
||||
navigateForResult(
|
||||
Constant.REQUEST_CODE_SCAN_QR_USER_ID,
|
||||
R.id.action_prepareCryptonitOtherApiWithdrawalFragment_to_qrScanFragment)
|
||||
}
|
||||
|
||||
ivRefreshBalance.setOnClickListener { doRequestBalance() }
|
||||
|
||||
cryptonit!!.setBalanceListener { response ->
|
||||
cryptonit.setBalanceListener { response ->
|
||||
when (ctx.blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestNet -> {
|
||||
tvBalance.text = response.eth_available
|
||||
|
|
@ -113,16 +106,17 @@ class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
rlProgressBar.visibility = View.INVISIBLE
|
||||
btnLoad.isActivated = true
|
||||
}
|
||||
cryptonit!!.setErrorListener { throwable ->
|
||||
cryptonit.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
cryptonit!!.setWithdrawalListener { response ->
|
||||
cryptonit.setWithdrawalListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.success != null && response.success!!) finish()
|
||||
else {
|
||||
if (response.success != null && response.success!!) {
|
||||
navigateUp()
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = response.reason!!.toString()
|
||||
}
|
||||
|
|
@ -131,42 +125,41 @@ class PrepareCryptonitOtherApiWithdrawalActivity : AppCompatActivity(), NfcAdapt
|
|||
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")) {
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.containsKey("QRCode")) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_SCAN_QR_KEY -> {
|
||||
cryptonit!!.key = data.getStringExtra("QRCode")
|
||||
tvKey!!.text = cryptonit!!.key
|
||||
cryptonit.key = data.getString("QRCode")
|
||||
tvKey?.text = cryptonit.key
|
||||
}
|
||||
Constant.REQUEST_CODE_SCAN_QR_SECRET -> {
|
||||
cryptonit!!.secret = data.getStringExtra("QRCode")
|
||||
tvSecret!!.text = cryptonit!!.secretDescription
|
||||
cryptonit.secret = data.getString("QRCode")
|
||||
tvSecret?.text = cryptonit.secretDescription
|
||||
}
|
||||
Constant.REQUEST_CODE_SCAN_QR_USER_ID -> {
|
||||
cryptonit!!.userId = data.getStringExtra("QRCode")
|
||||
tvUserID!!.text = cryptonit!!.userId
|
||||
cryptonit.userId = data.getString("QRCode")
|
||||
tvUserID?.text = cryptonit.userId
|
||||
}
|
||||
}
|
||||
cryptonit!!.saveAccountInfo()
|
||||
cryptonit.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doRequestBalance() {
|
||||
if (cryptonit!!.havaAccountInfo()) {
|
||||
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")
|
||||
cryptonit.requestBalance(ctx.blockchain.currency, "USD")
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
|
|
@ -1,54 +1,43 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.additional
|
||||
|
||||
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 androidx.appcompat.app.AppCompatActivity
|
||||
import android.text.InputFilter
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import com.tangem.data.network.Cryptonit
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.data.network.Cryptonit
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.util.DecimalDigitsInputFilter
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_cryptonit_withdrawal.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_prepare_cryptonit_withdrawal.*
|
||||
import java.io.IOException
|
||||
|
||||
class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCallback {
|
||||
class PrepareCryptonitWithdrawalFragment : BaseFragment(), NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareCryptonitWithdrawalActivity::class.java.simpleName
|
||||
val TAG: String = PrepareCryptonitWithdrawalFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fragment_prepare_cryptonit_withdrawal
|
||||
|
||||
private var cryptonit: Cryptonit? = null
|
||||
private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
|
||||
private val cryptonit: Cryptonit by lazy { Cryptonit(context) }
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_prepare_cryptonit_withdrawal)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
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)
|
||||
etUsername.setText(cryptonit.username)
|
||||
etPassword.setText(cryptonit.password)
|
||||
etFee.setText(cryptonit.fee)
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
|
|
@ -92,42 +81,42 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
val strAmount: String = etAmount.text.toString().replace(",", ".")
|
||||
val strFee: String = etFee.text.toString().replace(",", ".")
|
||||
val dblAmount: Double = strAmount.toDouble()
|
||||
cryptonit!!.fee = strFee
|
||||
cryptonit.fee = strFee
|
||||
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_withdrawal)
|
||||
|
||||
cryptonit!!.requestWithdrawCoins(ctx.blockchain.currency, dblAmount, ctx.coinData!!.wallet)
|
||||
cryptonit.requestWithdrawCoins(ctx.blockchain.currency, dblAmount, ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
}
|
||||
|
||||
ivRefreshBalance.setOnClickListener {
|
||||
cryptonit!!.username = etUsername.text.toString()
|
||||
cryptonit!!.password = etPassword.text.toString()
|
||||
cryptonit!!.saveAccountInfo()
|
||||
cryptonit.username = etUsername.text.toString()
|
||||
cryptonit.password = etPassword.text.toString()
|
||||
cryptonit.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
|
||||
cryptonit!!.setBalanceListener { response ->
|
||||
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 ->
|
||||
cryptonit.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
cryptonit!!.setWithdrawalListener { response ->
|
||||
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()
|
||||
Toast.makeText(context, R.string.withdrawal_successful, Toast.LENGTH_LONG).show();
|
||||
navigateUp()
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = response.errors.toString()
|
||||
|
|
@ -139,18 +128,18 @@ class PrepareCryptonitWithdrawalActivity : AppCompatActivity(), NfcAdapter.Reade
|
|||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun doRequestBalance() {
|
||||
if (cryptonit!!.haveAccountInfo()) {
|
||||
if (cryptonit.haveAccountInfo()) {
|
||||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.cryptonit_request_balance)
|
||||
tvError.visibility = View.INVISIBLE
|
||||
cryptonit!!.requestBalance(ctx.blockchain.currency)
|
||||
cryptonit.requestBalance(ctx.blockchain.currency)
|
||||
} else {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = getString(R.string.cryptonit_not_enough_account_data)
|
||||
|
|
@ -1,68 +1,51 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.additional
|
||||
|
||||
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 androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Toast
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.network.Kraken
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.data.network.Kraken
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.wallet.CoinEngineFactory
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_prepare_kraken_withdrawal.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_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 {
|
||||
class PrepareKrakenWithdrawalFragment : BaseFragment(), NavigationResultListener,
|
||||
NfcAdapter.ReaderCallback {
|
||||
|
||||
companion object {
|
||||
val TAG: String = PrepareKrakenWithdrawalActivity::class.java.simpleName
|
||||
val TAG: String = PrepareKrakenWithdrawalFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fragment_prepare_kraken_withdrawal
|
||||
|
||||
private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
|
||||
private val kraken: Kraken by lazy { Kraken(context) }
|
||||
|
||||
private var kraken: Kraken? = null
|
||||
private var fee: BigDecimal? = null
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
@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
|
||||
tvKey.text = kraken.key
|
||||
tvSecret.text = kraken.secretDescription
|
||||
|
||||
tvCardID.text = ctx.card!!.cidDescription
|
||||
tvWallet.text = ctx.coinData!!.wallet
|
||||
|
|
@ -93,18 +76,18 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
kraken!!.requestWithdrawInfo(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
kraken.requestWithdrawInfo(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ivCamera.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR) }
|
||||
// ivCamera.setOnClickListener { navigator.showQrScanActivity(this, Constant.REQUEST_CODE_SCAN_QR) }
|
||||
|
||||
ivRefreshBalance.setOnClickListener { doRequestBalance() }
|
||||
|
||||
kraken!!.setBalanceListener { response ->
|
||||
kraken.setBalanceListener { response ->
|
||||
if (response.error != null && response.error.isNotEmpty()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = Arrays.toString(response.error)
|
||||
|
|
@ -129,23 +112,23 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
}
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
}
|
||||
kraken!!.setErrorListener { throwable ->
|
||||
kraken.setErrorListener { throwable ->
|
||||
throwable.printStackTrace()
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
tvError.visibility = View.VISIBLE
|
||||
tvError.text = throwable.message
|
||||
}
|
||||
kraken!!.setWithdrawalListener { response ->
|
||||
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()
|
||||
Toast.makeText(context, "Withdrawal successful!", Toast.LENGTH_LONG).show()
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
kraken!!.setWithdrawalInfoListener { response ->
|
||||
kraken.setWithdrawalInfoListener { response ->
|
||||
rlProgressBar.visibility = View.INVISIBLE
|
||||
if (response.error != null && response.error.isNotEmpty()) {
|
||||
tvError.visibility = View.VISIBLE
|
||||
|
|
@ -167,7 +150,7 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
|
||||
|
||||
// Initialize a new instance of alert dialog builder object
|
||||
val builder = AlertDialog.Builder(this)
|
||||
val builder = AlertDialog.Builder(context)
|
||||
|
||||
// Set a title for alert dialog
|
||||
builder.setTitle(R.string.please_confirm_withdraw)
|
||||
|
|
@ -189,13 +172,13 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
rlProgressBar.visibility = View.VISIBLE
|
||||
tvProgressDescription.text = getString(R.string.kraken_request_withdrawal)
|
||||
|
||||
kraken!!.requestWithdraw(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
kraken.requestWithdraw(ctx.blockchain.currency, dblAmount.toString(), ctx.coinData!!.wallet)
|
||||
} catch (e: Exception) {
|
||||
etAmount.error = getString(R.string.unknown_amount_format)
|
||||
}
|
||||
}
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
Toast.makeText(this, R.string.operation_canceled, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, R.string.operation_canceled, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -226,30 +209,29 @@ class PrepareKrakenWithdrawalActivity : AppCompatActivity(), NfcAdapter.ReaderCa
|
|||
}
|
||||
}
|
||||
|
||||
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")) {
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.containsKey("QRCode")) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_SCAN_QR -> {
|
||||
val uri = URI(data.getStringExtra("QRCode"))
|
||||
val uri = URI(data.getString("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)
|
||||
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
|
||||
tvKey!!.text = kraken.key
|
||||
tvSecret!!.text = kraken.secretDescription
|
||||
}
|
||||
}
|
||||
kraken!!.saveAccountInfo()
|
||||
kraken.saveAccountInfo()
|
||||
doRequestBalance()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
nfcManager.ignoreTag(tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.pin
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
|
|
@ -6,87 +6,86 @@ 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 androidx.core.app.ActivityCompat
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import androidx.core.app.ActivityCompat
|
||||
import com.tangem.Constant
|
||||
import com.tangem.data.fingerprint.StartFingerprintReaderTask
|
||||
import com.tangem.card_android.android.reader.NfcManager
|
||||
import com.tangem.data.fingerprint.FingerprintHelper
|
||||
import com.tangem.wallet.TangemContext
|
||||
import com.tangem.card_android.android.data.PINStorage
|
||||
import com.tangem.card_android.android.nfc.NfcLifecycleObserver
|
||||
import com.tangem.card_android.data.loadFromBundle
|
||||
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.ui.activity.MainActivity
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.util.LOG
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_request.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_pin_request.*
|
||||
import kotlinx.android.synthetic.main.layout_pin_buttons.*
|
||||
import java.io.IOException
|
||||
|
||||
class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, FingerprintHelper.FingerprintHelperListener {
|
||||
class PinRequestFragment : BaseFragment(), NfcAdapter.ReaderCallback, FingerprintHelper.FingerprintHelperListener {
|
||||
companion object {
|
||||
val TAG: String = PinRequestActivity::class.java.simpleName
|
||||
val TAG: String = PinRequestFragment::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 callingIntent(mode: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
return bundle
|
||||
}
|
||||
|
||||
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 callingIntentRequestPin(mode: String, ctx: TangemContext, newPIN: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
ctx.saveToBundle(bundle)
|
||||
return bundle
|
||||
}
|
||||
|
||||
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(mode: String, ctx: TangemContext, newPIN2: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
ctx.saveToBundle(bundle)
|
||||
return bundle
|
||||
}
|
||||
|
||||
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 callingIntentRequestPin2(mode: String, ctx: TangemContext): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
ctx.saveToBundle(bundle)
|
||||
return bundle
|
||||
}
|
||||
|
||||
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 callingIntentConfirmPin(mode: String, newPIN: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
return bundle
|
||||
}
|
||||
|
||||
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
|
||||
fun callingIntentConfirmPin2(mode: String, newPIN2: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, mode)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
return bundle
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fragment_pin_request
|
||||
|
||||
val mode: Mode by lazy { Mode.valueOf(arguments?.getString(Constant.EXTRA_MODE) ?: "") }
|
||||
|
||||
lateinit var mode: Mode
|
||||
private var allowFingerprint = false
|
||||
var startFingerprintReaderTask: StartFingerprintReaderTask? = null
|
||||
private var fingerprintManager: FingerprintManager? = null
|
||||
|
|
@ -96,14 +95,8 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
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))
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
if (mode == Mode.RequestNewPIN)
|
||||
if (PINStorage.haveEncryptedPIN()) {
|
||||
|
|
@ -128,15 +121,14 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
else if (mode == Mode.ConfirmNewPIN2)
|
||||
tvPinPrompt.setText(R.string.confirm_new_pin_2)
|
||||
else if (mode == Mode.RequestPIN2) {
|
||||
val uid = intent.getStringExtra(EXTRA_TANGEM_CARD_UID)
|
||||
val uid = arguments?.getString(EXTRA_TANGEM_CARD_UID)
|
||||
val card = TangemCard(uid)
|
||||
card.loadFromBundle(intent.getBundleExtra(EXTRA_TANGEM_CARD))
|
||||
card.loadFromBundle(arguments?.getBundle(EXTRA_TANGEM_CARD) ?: Bundle())
|
||||
|
||||
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()
|
||||
navigateBackWithResult(Activity.RESULT_OK)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +192,7 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
override fun onTagDiscovered(tag: Tag) {
|
||||
try {
|
||||
Log.w(javaClass.name, "Ignore discovered tag!")
|
||||
nfcManager.ignoreTag(tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(tag)
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -216,28 +208,24 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
val cipher = result.cryptoObject.cipher
|
||||
|
||||
if (mode == Mode.RequestNewPIN || mode == Mode.ConfirmNewPIN) {
|
||||
val resultData = Intent()
|
||||
val resultData = Bundle()
|
||||
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()
|
||||
resultData.putString(Constant.EXTRA_NEW_PIN, pin)
|
||||
resultData.putString(Constant.EXTRA_CONFIRM_PIN, pin)
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
} else if (mode == Mode.RequestNewPIN2 || mode == Mode.ConfirmNewPIN2) {
|
||||
val resultData = Intent()
|
||||
val resultData = Bundle()
|
||||
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()
|
||||
resultData.putString(Constant.EXTRA_NEW_PIN_2, pin)
|
||||
resultData.putString(Constant.EXTRA_CONFIRM_PIN_2, pin)
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
} else if (mode == Mode.RequestPIN) {
|
||||
PINStorage.loadEncryptedPIN(cipher)
|
||||
setResult(Activity.RESULT_OK)
|
||||
navigateBackWithResult(Activity.RESULT_OK)
|
||||
} else if (mode == Mode.RequestPIN2) {
|
||||
PINStorage.loadEncryptedPIN2(cipher)
|
||||
setResult(Activity.RESULT_OK)
|
||||
navigateBackWithResult(Activity.RESULT_OK)
|
||||
}
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun buttonClick(button: Button) {
|
||||
|
|
@ -248,15 +236,15 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
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
|
||||
val keyguardManager = context?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
fingerprintManager = context?.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) {
|
||||
if (ActivityCompat.checkSelfPermission(context!!, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
|
||||
LOG.i(TAG, "User hasn't granted permission to use Fingerprint")
|
||||
return false
|
||||
}
|
||||
|
|
@ -278,8 +266,9 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
if (!allowFingerprint)
|
||||
return
|
||||
|
||||
fingerprintHelper = FingerprintHelper(this@PinRequestActivity)
|
||||
startFingerprintReaderTask = StartFingerprintReaderTask(this, fingerprintManager, fingerprintHelper)
|
||||
fingerprintHelper = FingerprintHelper(this@PinRequestFragment)
|
||||
startFingerprintReaderTask = StartFingerprintReaderTask(
|
||||
this@PinRequestFragment, fingerprintManager, fingerprintHelper)
|
||||
startFingerprintReaderTask!!.execute(null as Void?)
|
||||
}
|
||||
|
||||
|
|
@ -297,13 +286,13 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
var focusView: View? = null
|
||||
|
||||
if (mode == Mode.ConfirmNewPIN) {
|
||||
if (pin != intent.getStringExtra(Constant.EXTRA_NEW_PIN)) {
|
||||
if (pin != arguments?.getString(Constant.EXTRA_NEW_PIN)) {
|
||||
tvPin!!.error = getString(R.string.error_pin_confirmation_failed)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
}
|
||||
} else if (mode == Mode.ConfirmNewPIN2) {
|
||||
if (pin != intent.getStringExtra(Constant.EXTRA_NEW_PIN_2)) {
|
||||
if (pin != arguments?.getString(Constant.EXTRA_NEW_PIN_2)) {
|
||||
tvPin!!.error = getString(R.string.error_pin_confirmation_failed)
|
||||
focusView = tvPin
|
||||
cancel = true
|
||||
|
|
@ -320,31 +309,28 @@ class PinRequestActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Finge
|
|||
focusView!!.requestFocus()
|
||||
else {
|
||||
if (mode == Mode.RequestNewPIN || mode == Mode.ConfirmNewPIN) {
|
||||
val resultData = Intent()
|
||||
resultData.putExtra(Constant.EXTRA_NEW_PIN, pin)
|
||||
val resultData = Bundle()
|
||||
resultData.putString(Constant.EXTRA_NEW_PIN, pin)
|
||||
if (mode == Mode.ConfirmNewPIN)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN, pin)
|
||||
resultData.putString(Constant.EXTRA_CONFIRM_PIN, pin)
|
||||
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
|
||||
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)
|
||||
val resultData = Bundle()
|
||||
resultData.putString(Constant.EXTRA_NEW_PIN_2, pin)
|
||||
if (mode == Mode.ConfirmNewPIN2)
|
||||
resultData.putExtra(Constant.EXTRA_CONFIRM_PIN_2, pin)
|
||||
resultData.putString(Constant.EXTRA_CONFIRM_PIN_2, pin)
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
|
||||
setResult(Activity.RESULT_OK, resultData)
|
||||
finish()
|
||||
} else if (mode == Mode.RequestPIN) {
|
||||
PINStorage.setUserPIN(pin)
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
navigateBackWithResult(Activity.RESULT_OK)
|
||||
|
||||
} else if (mode == Mode.RequestPIN2) {
|
||||
PINStorage.setPIN2(pin)
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
navigateBackWithResult(Activity.RESULT_OK)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.pin
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
|
|
@ -6,7 +6,6 @@ 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
|
||||
|
|
@ -14,18 +13,18 @@ import android.os.Bundle
|
|||
import android.security.keystore.KeyGenParameterSpec
|
||||
import android.security.keystore.KeyPermanentlyInvalidatedException
|
||||
import android.security.keystore.KeyProperties
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.Toast
|
||||
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.card_android.android.data.PINStorage
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_save.*
|
||||
import kotlinx.android.synthetic.main.fragment_pin_save.*
|
||||
import kotlinx.android.synthetic.main.layout_pin_buttons.*
|
||||
import java.io.IOException
|
||||
import java.security.KeyStore
|
||||
|
|
@ -38,17 +37,13 @@ import javax.crypto.NoSuchPaddingException
|
|||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
|
||||
class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelperListener {
|
||||
class PinSaveFragment : BaseFragment(), 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
|
||||
}
|
||||
val TAG: String = PinSaveFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
override val layoutId = R.layout.fragment_pin_save
|
||||
|
||||
private var confirmWithFingerprintTask: ConfirmWithFingerprintTask? = null
|
||||
private var keyStore: KeyStore? = null
|
||||
private var cipher: Cipher? = null
|
||||
|
|
@ -63,11 +58,10 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
Save, DeleteEncryptedAndSave, Delete
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pin_save)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
usePIN2 = intent.getBooleanExtra(Constant.EXTRA_PIN2, false)
|
||||
usePIN2 = arguments?.getBoolean(Constant.EXTRA_PIN2, false) ?: false
|
||||
|
||||
if (usePIN2)
|
||||
tvPinPrompt.text = getString(R.string.enter_pin2_and_use_fingerprint_to_save_it)
|
||||
|
|
@ -130,7 +124,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
cipher = result.cryptoObject.cipher
|
||||
|
||||
when (onConfirmAction) {
|
||||
PinSaveActivity.OnConfirmAction.Save -> {
|
||||
OnConfirmAction.Save -> {
|
||||
val textToEncrypt = tvPin.text.toString()
|
||||
if (usePIN2) {
|
||||
PINStorage.saveEncryptedPIN2(cipher, textToEncrypt)
|
||||
|
|
@ -139,7 +133,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
}
|
||||
}
|
||||
|
||||
PinSaveActivity.OnConfirmAction.Delete -> {
|
||||
OnConfirmAction.Delete -> {
|
||||
if (usePIN2) {
|
||||
PINStorage.deleteEncryptedPIN2()
|
||||
} else {
|
||||
|
|
@ -149,7 +143,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
tvPin.text = ""
|
||||
}
|
||||
|
||||
PinSaveActivity.OnConfirmAction.DeleteEncryptedAndSave -> if (usePIN2) {
|
||||
OnConfirmAction.DeleteEncryptedAndSave -> if (usePIN2) {
|
||||
PINStorage.deleteEncryptedPIN2()
|
||||
PINStorage.saveEncryptedPIN2(cipher, tvPin.text.toString())
|
||||
} else {
|
||||
|
|
@ -159,7 +153,7 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
}
|
||||
|
||||
dFingerPrintConfirmation!!.dismiss()
|
||||
finish()
|
||||
navigateUp()
|
||||
}
|
||||
|
||||
fun getKeyStore(): Boolean {
|
||||
|
|
@ -288,19 +282,19 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
} else {
|
||||
if (usePIN2) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
tvPin.postDelayed({ navigateUp() }, 2000)
|
||||
return
|
||||
}
|
||||
|
||||
onConfirmAction = OnConfirmAction.Save
|
||||
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveFragment)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
|
||||
} else {
|
||||
if (cbUseFingerprint.isChecked || PINStorage.haveEncryptedPIN()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
tvPin.postDelayed({ navigateUp() }, 2000)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -311,11 +305,11 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
}
|
||||
|
||||
// show a progress spinner, and kick off a background task to perform the user login attempt
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveFragment)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
PINStorage.savePIN(tvPin.text.toString())
|
||||
finish()
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -325,50 +319,50 @@ class PinSaveActivity : AppCompatActivity(), FingerprintHelper.FingerprintHelper
|
|||
if (usePIN2) {
|
||||
if (PINStorage.haveEncryptedPIN2()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
tvPin.postDelayed({ navigateUp() }, 2000)
|
||||
return
|
||||
}
|
||||
onConfirmAction = OnConfirmAction.Delete
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveFragment)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
tvPin.text = ""
|
||||
finish()
|
||||
navigateUp()
|
||||
}
|
||||
} else {
|
||||
if (cbUseFingerprint.isChecked || PINStorage.haveEncryptedPIN()) {
|
||||
if (!testFingerPrintSettings()) {
|
||||
tvPin.postDelayed({ this.finish() }, 2000)
|
||||
tvPin.postDelayed({ navigateUp() }, 2000)
|
||||
return
|
||||
}
|
||||
onConfirmAction = OnConfirmAction.Delete
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveActivity)
|
||||
confirmWithFingerprintTask = ConfirmWithFingerprintTask(this@PinSaveFragment)
|
||||
confirmWithFingerprintTask!!.execute(null as Void?)
|
||||
} else {
|
||||
tvPin.text = ""
|
||||
PINStorage.deletePIN()
|
||||
finish()
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun testFingerPrintSettings(): Boolean {
|
||||
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
fingerprintManager = getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
|
||||
val keyguardManager = activity?.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
fingerprintManager = activity?.getSystemService(Context.FINGERPRINT_SERVICE) as FingerprintManager
|
||||
|
||||
if (!keyguardManager.isKeyguardSecure) {
|
||||
Toast.makeText(baseContext, R.string.user_has_not_enabled_lock_screen, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, R.string.user_has_not_enabled_lock_screen, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(baseContext, R.string.user_has_not_granted_permission_to_use_fingerprint, Toast.LENGTH_LONG).show()
|
||||
if (ActivityCompat.checkSelfPermission(context!!, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
|
||||
Toast.makeText(context, R.string.user_has_not_granted_permission_to_use_fingerprint, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
if (!fingerprintManager!!.hasEnrolledFingerprints()) {
|
||||
Toast.makeText(baseContext, R.string.user_has_not_registered_any_fingerprints, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, R.string.user_has_not_registered_any_fingerprints, Toast.LENGTH_LONG).show()
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -1,51 +1,48 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.pin
|
||||
|
||||
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 androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.Toast
|
||||
import com.tangem.App
|
||||
import com.tangem.Constant
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
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.*
|
||||
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.util.LOG
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_pin_swap.*
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import kotlinx.android.synthetic.main.fragment_pin_swap.*
|
||||
|
||||
class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
class PinSwapFragment : BaseFragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = PinSwapActivity::class.java.simpleName
|
||||
val TAG: String = PinSwapFragment::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
|
||||
fun callingIntent(newPIN: String, newPIN2: String): Bundle {
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN, newPIN)
|
||||
bundle.putString(Constant.EXTRA_NEW_PIN_2, newPIN2)
|
||||
return bundle
|
||||
}
|
||||
|
||||
const val RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER
|
||||
}
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
override val layoutId = R.layout.fragment_pin_swap
|
||||
|
||||
private lateinit var card: TangemCard;
|
||||
private var newPIN: String? = null
|
||||
|
|
@ -55,23 +52,22 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
|
||||
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(arguments?.getString(EXTRA_TANGEM_CARD_UID))
|
||||
card.loadFromBundle(arguments?.getBundle(EXTRA_TANGEM_CARD) ?: Bundle())
|
||||
|
||||
card = TangemCard(intent.getStringExtra(EXTRA_TANGEM_CARD_UID))
|
||||
newPIN = arguments?.getString(Constant.EXTRA_NEW_PIN)
|
||||
newPIN2 = arguments?.getString(Constant.EXTRA_NEW_PIN_2)
|
||||
}
|
||||
|
||||
card.loadFromBundle(intent.extras!!.getBundle(EXTRA_TANGEM_CARD))
|
||||
|
||||
newPIN = intent.getStringExtra(Constant.EXTRA_NEW_PIN)
|
||||
newPIN2 = intent.getStringExtra(Constant.EXTRA_NEW_PIN_2)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
tvCardID.text = card.cidDescription
|
||||
|
||||
progressBar = findViewById(R.id.progressBar)
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
}
|
||||
|
|
@ -84,10 +80,11 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
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 = SwapPINTask(card, NfcReader((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, this, newPIN, newPIN2)
|
||||
swapPinTask?.start()
|
||||
} else {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -119,11 +116,10 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
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()
|
||||
val data = Bundle()
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
cardProtocol.error is CardProtocol.TangemException_InvalidPIN -> {
|
||||
progressBar!!.post {
|
||||
|
|
@ -135,12 +131,11 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
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()
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MESSAGE, "Cannot change PIN(s). Make sure you enter correct PIN2!")
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
navigateBackWithResult(RESULT_INVALID_PIN, data)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -149,10 +144,11 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
else -> progressBar!!.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed) {
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
NoExtendedLengthSupportDialog().show(activity!!.supportFragmentManager,
|
||||
NoExtendedLengthSupportDialog.TAG)
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(baseContext, R.string.try_to_scan_again, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, R.string.try_to_scan_again, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
progressBar!!.progress = 100
|
||||
progressBar!!.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
|
|
@ -190,15 +186,15 @@ class PinSwapActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProt
|
|||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
WaitSecurityDelayDialog.onReadWait(activity, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(activity, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(activity)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.wallet
|
||||
|
||||
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
|
||||
|
|
@ -11,57 +9,42 @@ 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.wallet.TangemContext
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
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.activity.MainActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_create_new_wallet.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_create_new_wallet.*
|
||||
import kotlinx.android.synthetic.main.layout_progress_horizontal.*
|
||||
import kotlinx.android.synthetic.main.layout_touch_card.*
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
|
||||
class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
class CreateNewWalletFragment : BaseFragment(), 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
|
||||
}
|
||||
}
|
||||
override val layoutId = R.layout.fragment_create_new_wallet
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
|
||||
|
||||
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)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// init NFC Antenna
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(this, ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna = NfcDeviceAntennaLocation(requireContext(), ivHandCardHorizontal, ivHandCardVertical, llHand, llNfc)
|
||||
nfcDeviceAntenna.init()
|
||||
|
||||
tvCardId.text = ctx.card!!.cidDescription
|
||||
|
|
@ -81,13 +64,14 @@ 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((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, this)
|
||||
createNewWalletTask?.start()
|
||||
} else
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
override fun onPause() {
|
||||
createNewWalletTask?.cancel(true)
|
||||
super.onPause()
|
||||
}
|
||||
|
|
@ -110,11 +94,11 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
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()
|
||||
val data = Bundle()
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card.asBundle)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
return@post
|
||||
}
|
||||
} else {
|
||||
lastReadSuccess = false
|
||||
|
|
@ -128,12 +112,12 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
progressBar?.progress = 0
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.DKGRAY)
|
||||
progressBar?.visibility = View.INVISIBLE
|
||||
val intent = Intent()
|
||||
intent.putExtra(Constant.EXTRA_MESSAGE, getString(R.string.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()
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MESSAGE, getString(R.string.cannot_create_wallet))
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, cardProtocol.card.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, cardProtocol.card!!.asBundle)
|
||||
navigateBackWithResult(Constant.RESULT_INVALID_PIN, data)
|
||||
return@postDelayed
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
@ -142,10 +126,10 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
progressBar?.post {
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed) {
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
NoExtendedLengthSupportDialog().show(activity!!.supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
}
|
||||
} else
|
||||
Toast.makeText(this, R.string.try_to_scan_again, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(context, R.string.try_to_scan_again, Toast.LENGTH_SHORT).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
|
|
@ -178,15 +162,15 @@ class CreateNewWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback,
|
|||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
WaitSecurityDelayDialog.onReadWait(activity, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(activity, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(activity)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.ui.activity
|
||||
package com.tangem.ui.fragment.wallet
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
|
|
@ -10,51 +10,45 @@ import android.nfc.Tag
|
|||
import android.nfc.tech.IsoDep
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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.wallet.TangemContext
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
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.util.UtilHelper
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.ui.fragment.pin.PinRequestFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.wallet.R
|
||||
import kotlinx.android.synthetic.main.activity_empty_wallet.*
|
||||
import com.tangem.wallet.TangemContext
|
||||
import kotlinx.android.synthetic.main.fragment_empty_wallet.*
|
||||
import kotlinx.android.synthetic.main.layout_tangem_card.*
|
||||
import javax.inject.Inject
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD
|
||||
import com.tangem.card_android.data.EXTRA_TANGEM_CARD_UID
|
||||
import com.tangem.di.ToastHelper
|
||||
|
||||
class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
class EmptyWalletFragment : BaseFragment(), NavigationResultListener,
|
||||
NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
companion object {
|
||||
val TAG: String = EmptyWalletActivity::class.java.simpleName
|
||||
val TAG: String = EmptyWalletFragment::class.java.simpleName
|
||||
fun callingIntent(context: Context, ctx: TangemContext): Intent {
|
||||
val intent = Intent(context, EmptyWalletActivity::class.java)
|
||||
val intent = Intent(context, EmptyWalletFragment::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
internal lateinit var navigator: Navigator
|
||||
@Inject
|
||||
internal lateinit var toastHelper: ToastHelper
|
||||
override val layoutId = R.layout.fragment_empty_wallet
|
||||
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var ctx: TangemContext
|
||||
private val ctx: TangemContext by lazy { TangemContext.loadFromBundle(context, arguments) }
|
||||
|
||||
private var lastReadSuccess = true
|
||||
private var verifyCardTask: VerifyCardTask? = null
|
||||
|
|
@ -62,17 +56,8 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
|
||||
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)
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
tvIssuer.text = ctx.card!!.issuerDescription
|
||||
|
||||
|
|
@ -91,52 +76,63 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, 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)
|
||||
|
||||
val data = Bundle()
|
||||
data.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
data.putString(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
data.putBundle(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2,
|
||||
R.id.action_emptyWalletFragment_to_pinRequestFragment, data)
|
||||
}
|
||||
|
||||
btnDetails.setOnClickListener {
|
||||
if (cardProtocol != null)
|
||||
navigator.showVerifyCard(this, ctx)
|
||||
else
|
||||
toastHelper.showSingleToast(this, getString(R.string.need_attach_card_again))
|
||||
if (cardProtocol != null) {
|
||||
val data = Bundle()
|
||||
ctx.saveToBundle(data)
|
||||
navigateForResult(Constant.REQUEST_CODE_VERIFY_CARD,
|
||||
R.id.action_emptyWalletFragment_to_verifyCard, data)
|
||||
} else {
|
||||
(activity as MainActivity).toastHelper
|
||||
.showSingleToast(context, getString(R.string.need_attach_card_again))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
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)
|
||||
data.putString(Constant.EXTRA_MODIFICATION, "updateAndViewCard")
|
||||
data.putInt("updateDelay", 0)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
finish()
|
||||
return
|
||||
} 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))
|
||||
if (data != null && data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(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)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
bundle.putString(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
bundle.putBundle(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2,
|
||||
R.id.action_emptyWalletFragment_to_pinRequestFragment, bundle)
|
||||
return
|
||||
}
|
||||
}
|
||||
setResult(resultCode, data)
|
||||
finish()
|
||||
navigateBackWithResult(resultCode, data)
|
||||
return
|
||||
} else if (requestCode == Constant.REQUEST_CODE_REQUEST_PIN2) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
navigator.showCreateNewWallet(this, ctx)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(EXTRA_TANGEM_CARD_UID, ctx.card!!.uid)
|
||||
bundle.putBundle(EXTRA_TANGEM_CARD, ctx.card!!.asBundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_CREATE_NEW_WALLET_ACTIVITY,
|
||||
R.id.action_emptyWalletFragment_to_createNewWalletFragment, bundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +143,7 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
val uid = tag.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (ctx.card.uid != sUID) {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +152,8 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
else
|
||||
isoDep.timeout = 65000
|
||||
|
||||
verifyCardTask = VerifyCardTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, App.firmwaresStorage, this)
|
||||
verifyCardTask = VerifyCardTask(ctx.card, NfcReader((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, App.firmwaresStorage, this)
|
||||
verifyCardTask?.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -189,9 +186,9 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
lastReadSuccess = false
|
||||
if (cardProtocol.error is CardProtocol.TangemException_ExtendedLengthNotSupported) {
|
||||
if (!NoExtendedLengthSupportDialog.allReadyShowed)
|
||||
NoExtendedLengthSupportDialog().show(supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
NoExtendedLengthSupportDialog().show(activity!!.supportFragmentManager, NoExtendedLengthSupportDialog.TAG)
|
||||
} else
|
||||
Toast.makeText(this@EmptyWalletActivity, R.string.try_to_scan_again, Toast.LENGTH_LONG).show()
|
||||
Toast.makeText(context, R.string.try_to_scan_again, Toast.LENGTH_LONG).show()
|
||||
|
||||
progressBar?.progress = 100
|
||||
progressBar?.progressTintList = ColorStateList.valueOf(Color.RED)
|
||||
|
|
@ -219,7 +216,7 @@ 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() {
|
||||
|
|
@ -245,15 +242,15 @@ class EmptyWalletActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, Card
|
|||
}
|
||||
|
||||
override fun onReadWait(msec: Int) {
|
||||
WaitSecurityDelayDialog.onReadWait(this, msec)
|
||||
WaitSecurityDelayDialog.onReadWait(activity, msec)
|
||||
}
|
||||
|
||||
override fun onReadBeforeRequest(timeout: Int) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(this, timeout)
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(activity, timeout)
|
||||
}
|
||||
|
||||
override fun onReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(this)
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(activity)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.ui.fragment
|
||||
package com.tangem.ui.fragment.wallet
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
|
|
@ -14,9 +14,7 @@ import android.os.Build
|
|||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
|
|
@ -24,8 +22,6 @@ import androidx.lifecycle.Observer
|
|||
import androidx.lifecycle.ViewModelProviders
|
||||
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
|
||||
|
|
@ -39,10 +35,7 @@ import com.tangem.data.dp.PrefsManager
|
|||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.server_android.ServerApiTangem
|
||||
import com.tangem.server_android.model.CardVerifyAndGetInfo
|
||||
import com.tangem.ui.activity.LoadedWalletActivity
|
||||
import com.tangem.ui.activity.PinRequestActivity
|
||||
import com.tangem.ui.activity.PrepareCryptonitWithdrawalActivity
|
||||
import com.tangem.ui.activity.PrepareKrakenWithdrawalActivity
|
||||
import com.tangem.ui.activity.MainActivity
|
||||
import com.tangem.ui.dialog.NoExtendedLengthSupportDialog
|
||||
import com.tangem.ui.dialog.PINSwapWarningDialog
|
||||
import com.tangem.ui.dialog.ShowQRCodeDialog
|
||||
|
|
@ -50,6 +43,10 @@ import com.tangem.ui.dialog.WaitSecurityDelayDialog
|
|||
import com.tangem.ui.event.DeletingWalletFinish
|
||||
import com.tangem.ui.event.TransactionFinishWithError
|
||||
import com.tangem.ui.event.TransactionFinishWithSuccess
|
||||
import com.tangem.ui.fragment.BaseFragment
|
||||
import com.tangem.ui.fragment.pin.PinRequestFragment
|
||||
import com.tangem.ui.fragment.pin.PinSwapFragment
|
||||
import com.tangem.ui.navigation.NavigationResultListener
|
||||
import com.tangem.util.LOG
|
||||
import com.tangem.util.UtilHelper
|
||||
import com.tangem.wallet.*
|
||||
|
|
@ -62,14 +59,16 @@ import java.io.InputStream
|
|||
import java.util.*
|
||||
import kotlin.concurrent.timerTask
|
||||
|
||||
class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
class LoadedWalletFragment : BaseFragment(), NavigationResultListener, NfcAdapter.ReaderCallback,
|
||||
CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
companion object {
|
||||
val TAG: String = LoadedWalletFragment::class.java.simpleName
|
||||
}
|
||||
|
||||
override val layoutId = R.layout.fr_loaded_wallet
|
||||
|
||||
private lateinit var viewModel: LoadedWalletViewModel
|
||||
private lateinit var ctx: TangemContext
|
||||
private lateinit var nfcManager: NfcManager
|
||||
private lateinit var mpSecondScanSound: MediaPlayer
|
||||
private var serverApiCommon: ServerApiCommon = ServerApiCommon()
|
||||
private var serverApiTangem: ServerApiTangem = ServerApiTangem()
|
||||
|
|
@ -111,23 +110,21 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
ctx = TangemContext.loadFromBundle(activity, activity?.intent?.extras)
|
||||
|
||||
nfcManager = NfcManager(activity!!, this)
|
||||
lifecycle.addObserver(NfcLifecycleObserver(nfcManager))
|
||||
ctx = TangemContext.loadFromBundle(context, arguments)
|
||||
|
||||
lastTag = activity?.intent?.getParcelableExtra(Constant.EXTRA_LAST_DISCOVERED_TAG)
|
||||
|
||||
mpSecondScanSound = MediaPlayer.create(activity, R.raw.scan_card_sound)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.fr_loaded_wallet, container, false)
|
||||
if (arguments?.containsKey(NfcAdapter.EXTRA_TAG) == true) {
|
||||
val tag = arguments!!.getParcelable<Tag>(NfcAdapter.EXTRA_TAG)
|
||||
if (tag != null) onTagDiscovered(tag)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
mpSecondScanSound = MediaPlayer.create(activity, R.raw.scan_card_sound)
|
||||
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
tvBalance.setSingleLine(!engine!!.needMultipleLinesForBalance())
|
||||
|
|
@ -160,7 +157,7 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
intent.addCategory(Intent.CATEGORY_DEFAULT)
|
||||
startActivity(intent)
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
(activity as LoadedWalletActivity).toastHelper.showSingleToast(context, getString(R.string.no_compatible_wallet))
|
||||
(activity as MainActivity).toastHelper.showSingleToast(context, getString(R.string.no_compatible_wallet))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,15 +170,19 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
}
|
||||
|
||||
getString(R.string.via_cryptonit) -> {
|
||||
val intent = Intent(activity, PrepareCryptonitWithdrawalActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_TRANSACTION)
|
||||
navigateForResult(
|
||||
Constant.REQUEST_CODE_RECEIVE_TRANSACTION,
|
||||
R.id.action_loadedWalletFragment_to_prepareCryptonitWithdrawalFragment,
|
||||
Bundle().apply { ctx.saveToBundle(this) }
|
||||
)
|
||||
}
|
||||
|
||||
getString(R.string.via_kraken) -> {
|
||||
val intent = Intent(activity, PrepareKrakenWithdrawalActivity::class.java)
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_RECEIVE_TRANSACTION)
|
||||
navigateForResult(
|
||||
Constant.REQUEST_CODE_RECEIVE_TRANSACTION,
|
||||
R.id.action_loadedWalletFragment_to_prepareKrakenWithdrawalFragment,
|
||||
Bundle().apply { ctx.saveToBundle(this) }
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
|
|
@ -195,24 +196,34 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
|
||||
btnExtract.setOnClickListener {
|
||||
if (UtilHelper.isOnline(context as Activity))
|
||||
if (!engine.isExtractPossible)
|
||||
(activity as LoadedWalletActivity).toastHelper.showSingleToast(context, ctx.message)
|
||||
else if (ctx.card!!.remainingSignatures == 0)
|
||||
(activity as LoadedWalletActivity).toastHelper.showSingleToast(context, getString(R.string.card_has_no_remaining_signature))
|
||||
else
|
||||
(activity as LoadedWalletActivity).navigator.showPrepareTransaction(context as Activity, ctx)
|
||||
if (!engine.isExtractPossible) {
|
||||
(activity as MainActivity).toastHelper.showSingleToast(context, ctx.message)
|
||||
} else if (ctx.card!!.remainingSignatures == 0) {
|
||||
(activity as MainActivity).toastHelper.showSingleToast(context, getString(R.string.card_has_no_remaining_signature))
|
||||
} else {
|
||||
val bundle = Bundle().apply { ctx.saveToBundle(this) }
|
||||
navigateForResult(Constant.REQUEST_CODE_SEND_TRANSACTION,
|
||||
R.id.action_loadedWalletFragment_to_prepareTransactionFragment, bundle)
|
||||
}
|
||||
else
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
btnDetails.setOnClickListener {
|
||||
if (cardProtocol != null)
|
||||
(activity as LoadedWalletActivity).navigator.showVerifyCard(context as Activity, ctx)
|
||||
else
|
||||
(activity as LoadedWalletActivity).toastHelper.showSingleToast(context, getString(R.string.need_attach_card_again))
|
||||
if (cardProtocol != null) {
|
||||
val bundle = Bundle().apply { ctx.saveToBundle(this) }
|
||||
navigateForResult(Constant.REQUEST_CODE_VERIFY_CARD,
|
||||
R.id.action_loadedWalletFragment_to_verifyCard, bundle)
|
||||
} else {
|
||||
(activity as MainActivity).toastHelper
|
||||
.showSingleToast(context, getString(R.string.need_attach_card_again))
|
||||
}
|
||||
}
|
||||
|
||||
btnNewScan.setOnClickListener { (activity as LoadedWalletActivity).navigator.showMain(context as Activity) }
|
||||
btnNewScan.setOnClickListener {
|
||||
// navigateToDestination(R.id.action_loadedWalletFragment_to_main)
|
||||
navigateUp()
|
||||
}
|
||||
|
||||
// request card verify and get info listener
|
||||
val cardVerifyAndGetInfoListener: ServerApiTangem.CardVerifyAndGetInfoListener = object : ServerApiTangem.CardVerifyAndGetInfoListener {
|
||||
|
|
@ -334,31 +345,52 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
|
||||
@Subscribe
|
||||
fun onDeleteWalletFinish(deletingWalletFinish: DeletingWalletFinish) {
|
||||
activity?.finish()
|
||||
navigateUp()
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
override fun onNavigationResult(requestCode: String, resultCode: Int, data: Bundle?) {
|
||||
when (requestCode) {
|
||||
Constant.REQUEST_CODE_VERIFY_CARD ->
|
||||
// action after erase wallet
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
activity?.finish()
|
||||
navigateUp()
|
||||
|
||||
Constant.REQUEST_CODE_ENTER_NEW_PIN -> if (resultCode == Activity.RESULT_OK)
|
||||
if (data != null)
|
||||
if (data.extras != null && data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN))
|
||||
(activity as LoadedWalletActivity).navigator.showPinRequestRequestPin(context as Activity, PinRequestActivity.Mode.RequestPIN.toString(), ctx, data.getStringExtra(Constant.EXTRA_NEW_PIN))
|
||||
else
|
||||
(activity as LoadedWalletActivity).navigator.showPinRequestConfirmNewPin(context as Activity, PinRequestActivity.Mode.ConfirmNewPIN.toString(), data.getStringExtra(Constant.EXTRA_NEW_PIN))
|
||||
if (data.containsKey(Constant.EXTRA_CONFIRM_PIN)) {
|
||||
val bundle = PinRequestFragment.callingIntentRequestPin(
|
||||
PinRequestFragment.Mode.RequestPIN.toString(), ctx,
|
||||
data.getString(Constant.EXTRA_NEW_PIN) ?: "")
|
||||
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment,
|
||||
bundle)
|
||||
} else {
|
||||
val bundle = PinRequestFragment.callingIntentConfirmPin(
|
||||
PinRequestFragment.Mode.ConfirmNewPIN.toString(),
|
||||
data.getString(Constant.EXTRA_NEW_PIN) ?: "")
|
||||
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment, bundle)
|
||||
}
|
||||
|
||||
|
||||
Constant.REQUEST_CODE_ENTER_NEW_PIN2 -> if (resultCode == Activity.RESULT_OK)
|
||||
if (data != null)
|
||||
if (data.extras != null && data.extras!!.containsKey(Constant.EXTRA_CONFIRM_PIN_2))
|
||||
(activity as LoadedWalletActivity).navigator.showPinRequestRequestPin2(context as Activity, PinRequestActivity.Mode.RequestPIN2.toString(), ctx, data.getStringExtra(Constant.EXTRA_NEW_PIN_2))
|
||||
else
|
||||
(activity as LoadedWalletActivity).navigator.showPinRequestConfirmNewPin2(context as Activity, PinRequestActivity.Mode.ConfirmNewPIN2.toString(), data.getStringExtra(Constant.EXTRA_NEW_PIN_2))
|
||||
if (data.containsKey(Constant.EXTRA_CONFIRM_PIN_2)) {
|
||||
val bundle = PinRequestFragment.callingIntentRequestPin2(
|
||||
PinRequestFragment.Mode.RequestPIN2.toString(), ctx,
|
||||
data.getString(Constant.EXTRA_NEW_PIN_2))
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment, bundle)
|
||||
|
||||
} else {
|
||||
val bundle = PinRequestFragment.callingIntentConfirmPin2(
|
||||
PinRequestFragment.Mode.ConfirmNewPIN2.toString(),
|
||||
data.getString(Constant.EXTRA_NEW_PIN_2))
|
||||
navigateForResult(Constant.REQUEST_CODE_ENTER_NEW_PIN2,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment, bundle)
|
||||
}
|
||||
|
||||
Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (newPIN == "")
|
||||
|
|
@ -368,7 +400,10 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
newPIN2 = App.pinStorage.piN2
|
||||
|
||||
val pinSwapWarningDialog = PINSwapWarningDialog()
|
||||
pinSwapWarningDialog.setOnRefreshPage { (activity as LoadedWalletActivity).navigator.showPinSwap(context as Activity, newPIN, newPIN2) }
|
||||
pinSwapWarningDialog.setOnRefreshPage {
|
||||
val bundle = PinSwapFragment.callingIntent(newPIN, newPIN2)
|
||||
navigateForResult(Constant.REQUEST_CODE_SWAP_PIN, R.id.pinSwapFragment, bundle)
|
||||
}
|
||||
val bundle = Bundle()
|
||||
if (!CardProtocol.isDefaultPIN(newPIN) || !CardProtocol.isDefaultPIN2(newPIN2))
|
||||
bundle.putString(Constant.EXTRA_MESSAGE, getString(R.string.if_you_forget))
|
||||
|
|
@ -380,59 +415,65 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
|
||||
Constant.REQUEST_CODE_SWAP_PIN -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
ctx.saveToIntent(data)
|
||||
data?.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
} else
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
|
||||
activity?.setResult(Activity.RESULT_OK, data)
|
||||
activity?.finish()
|
||||
val resultData = Bundle()
|
||||
ctx.saveToBundle(resultData)
|
||||
resultData.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
} else {
|
||||
data.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
|
||||
} else {
|
||||
if (data != null && data.extras != 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))
|
||||
if (data != null && data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
(activity as LoadedWalletActivity).navigator.showPinRequestRequestPin2(context as Activity, PinRequestActivity.Mode.RequestPIN2.toString(), ctx)
|
||||
val bundle = PinRequestFragment.callingIntentRequestPin2(
|
||||
PinRequestFragment.Mode.RequestPIN2.toString(), ctx)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment, bundle)
|
||||
return
|
||||
} else {
|
||||
if (data != null && data.extras!!.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getStringExtra(Constant.EXTRA_MESSAGE)
|
||||
if (data != null && data.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getString(Constant.EXTRA_MESSAGE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Constant.REQUEST_CODE_PURGE -> if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
ctx.saveToIntent(data)
|
||||
data?.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
} else
|
||||
data.putExtra(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
|
||||
activity?.setResult(Activity.RESULT_OK, data)
|
||||
activity?.finish()
|
||||
val resultData = Bundle()
|
||||
ctx.saveToBundle(resultData)
|
||||
resultData.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_DELETE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, resultData)
|
||||
} else {
|
||||
data.putString(Constant.EXTRA_MODIFICATION, Constant.EXTRA_MODIFICATION_UPDATE)
|
||||
navigateBackWithResult(Activity.RESULT_OK, data)
|
||||
}
|
||||
|
||||
} else {
|
||||
if (data != null && data.extras != 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))
|
||||
if (data != null && data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
if (resultCode == Constant.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++
|
||||
|
||||
val intent = Intent(activity, PinRequestActivity::class.java)
|
||||
intent.putExtra(Constant.EXTRA_MODE, PinRequestActivity.Mode.RequestPIN2.toString())
|
||||
ctx.saveToIntent(intent)
|
||||
startActivityForResult(intent, Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE)
|
||||
val bundle = Bundle()
|
||||
bundle.putString(Constant.EXTRA_MODE, PinRequestFragment.Mode.RequestPIN2.toString())
|
||||
ctx.saveToBundle(bundle)
|
||||
navigateForResult(Constant.REQUEST_CODE_REQUEST_PIN2_FOR_PURGE,
|
||||
R.id.action_loadedWalletFragment_to_pinRequestFragment, bundle)
|
||||
|
||||
return
|
||||
} else {
|
||||
if (data != null && data.extras!!.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getStringExtra(Constant.EXTRA_MESSAGE)
|
||||
if (data != null && data.containsKey(Constant.EXTRA_MESSAGE)) {
|
||||
ctx.error = data.getString(Constant.EXTRA_MESSAGE)
|
||||
}
|
||||
}
|
||||
updateViews()
|
||||
|
|
@ -446,10 +487,10 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
updateViews()
|
||||
}
|
||||
|
||||
if (data != null && data.extras != null) {
|
||||
if (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))
|
||||
if (data != null) {
|
||||
if (data.containsKey(EXTRA_TANGEM_CARD_UID) && data.containsKey(EXTRA_TANGEM_CARD)) {
|
||||
val updatedCard = TangemCard(data.getString(EXTRA_TANGEM_CARD_UID))
|
||||
updatedCard.loadFromBundle(data.getBundle(EXTRA_TANGEM_CARD))
|
||||
ctx.card = updatedCard
|
||||
}
|
||||
}
|
||||
|
|
@ -745,7 +786,7 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
val uid = tag?.id
|
||||
val sUID = Util.byteArrayToHexString(uid)
|
||||
if (ctx.card.uid != sUID || cardProtocol != null) {
|
||||
nfcManager.ignoreTag(isoDep.tag)
|
||||
(activity as MainActivity).nfcManager.ignoreTag(isoDep.tag)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -754,7 +795,8 @@ class LoadedWalletFragment : androidx.fragment.app.Fragment(), NfcAdapter.Reader
|
|||
else
|
||||
isoDep.timeout = 65000
|
||||
|
||||
verifyCardTask = VerifyCardTask(ctx.card, NfcReader(nfcManager, isoDep), App.localStorage, App.pinStorage, App.firmwaresStorage, this)
|
||||
verifyCardTask = VerifyCardTask(ctx.card, NfcReader((activity as MainActivity).nfcManager, isoDep),
|
||||
App.localStorage, App.pinStorage, App.firmwaresStorage, this)
|
||||
verifyCardTask?.start()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package com.tangem.ui.fragment
|
||||
package com.tangem.ui.fragment.wallet
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.tangem.data.Blockchain
|
||||
import com.tangem.data.network.ServerApiCommon
|
||||
import com.tangem.data.network.ServerApiCommon.RateInfoListener
|
||||
import com.tangem.data.network.model.RateInfoResponse
|
||||
Loading…
Add table
Add a link
Reference in a new issue