From f4dbd4e93be30ce8a5f7d5b2e412525b3255e212 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 25 Oct 2017 21:33:38 -0400 Subject: [PATCH] - Send view created, along with its Validators. - Currency Spinner Adapter created - Send activity and layout created --- .../activities/ImportSeedActivity.java | 6 +- .../activities/SendTransactionActivity.java | 209 ++++++ .../dao/CryptoCoinBalanceDao.java | 3 + .../crystalwallet/dao/CryptoCurrencyDao.java | 3 + .../validators/ImportSeedValidator.java | 5 + .../validators/SendTransactionValidator.java | 36 + .../viewmodels/validators/UIValidator.java | 4 +- .../validators/UIValidatorListener.java | 2 + .../AmountValidationField.java | 63 ++ .../AssetValidationField.java | 31 + ...tsharesAccountMnemonicValidationField.java | 2 +- .../BitsharesAccountNameValidationField.java | 4 +- .../validationfields/FromValidationField.java | 45 ++ .../validationfields/MemoValidationField.java | 29 + .../PinConfirmationValidationField.java | 3 +- .../PinValidationField.java | 4 +- .../validationfields/ToValidationField.java | 48 ++ .../ValidationField.java | 4 +- .../views/CryptoCurrencyAdapter.java | 40 + .../layout/crypto_currency_adapter_item.xml | 16 + app/src/main/res/layout/send_transaction.xml | 706 +++--------------- 21 files changed, 630 insertions(+), 633 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AmountValidationField.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AssetValidationField.java rename app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/{ => validationfields}/BitsharesAccountMnemonicValidationField.java (96%) rename app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/{ => validationfields}/BitsharesAccountNameValidationField.java (90%) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/FromValidationField.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/MemoValidationField.java rename app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/{ => validationfields}/PinConfirmationValidationField.java (93%) rename app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/{ => validationfields}/PinValidationField.java (85%) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ToValidationField.java rename app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/{ => validationfields}/ValidationField.java (92%) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java create mode 100644 app/src/main/res/layout/crypto_currency_adapter_item.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java index 26a1733..26e3541 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java @@ -1,6 +1,5 @@ package cy.agorise.crystalwallet.activities; -import android.app.Activity; import android.arch.lifecycle.ViewModelProviders; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; @@ -14,19 +13,16 @@ import butterknife.ButterKnife; import butterknife.OnClick; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.enums.SeedType; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoNetAccount; -import cy.agorise.crystalwallet.models.GrapheneAccount; import cy.agorise.crystalwallet.models.GrapheneAccountInfo; import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; import cy.agorise.crystalwallet.viewmodels.GrapheneAccountInfoViewModel; import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; -import cy.agorise.crystalwallet.viewmodels.validators.ValidationField; -import cy.agorise.crystalwallet.views.CryptoNetBalanceListView; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; public class ImportSeedActivity extends AppCompatActivity implements UIValidatorListener { diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java new file mode 100644 index 0000000..111fade --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java @@ -0,0 +1,209 @@ +package cy.agorise.crystalwallet.activities; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.text.Editable; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.SimpleAdapter; +import android.widget.Spinner; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnTextChanged; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.enums.CryptoNet; +import cy.agorise.crystalwallet.enums.SeedType; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccountInfo; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; +import cy.agorise.crystalwallet.viewmodels.GrapheneAccountInfoViewModel; +import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; +import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; + +public class SendTransactionActivity extends AppCompatActivity implements UIValidatorListener { + + SendTransactionValidator sendTransactionValidator; + + @BindView(R.id.etFrom) + EditText etFrom; + @BindView(R.id.tvFromError) + TextView tvFromError; + @BindView(R.id.etTo) + EditText etTo; + @BindView(R.id.tvToError) + TextView tvToError; + @BindView(R.id.spAsset) + Spinner spAsset; + @BindView(R.id.tvAssetError) + TextView tvAssetError; + @BindView(R.id.etAmount) + EditText etAmount; + @BindView(R.id.tvAmountError) + TextView tvAmountError; + @BindView (R.id.etMemo) + EditText etMemo; + @BindView(R.id.tvMemoError) + TextView tvMemoError; + @BindView(R.id.btnSend) + Button btnSend; + @BindView(R.id.btnCancel) + Button btnCancel; + + private long cryptoNetAccountId; + private CryptoNetAccount cryptoNetAccount; + private CrystalDatabase db; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.send_transaction); + + ButterKnife.bind(this); + + btnSend.setEnabled(false); + + this.cryptoNetAccountId = getIntent().getLongExtra("CRYPTO_NET_ACCOUNT_ID", -1); + + if (this.cryptoNetAccountId != -1) { + db = CrystalDatabase.getAppDatabase(this); + this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); + final LiveData> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId); + balancesList.observe(this, new Observer>() { + @Override + public void onChanged(@Nullable List cryptoCoinBalances) { + ArrayList assetIds = new ArrayList(); + ArrayList assetLabels = new ArrayList(); + for (CryptoCoinBalance nextBalance : balancesList.getValue()) { + assetIds.add(nextBalance.getCryptoCurrencyId()); + } + List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); + for (CryptoCurrency nextCurrency : cryptoCurrencyList) { + assetLabels.add(nextCurrency.getName()); + } + + ArrayAdapter assetAdapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, assetLabels); + spAsset.setAdapter(assetAdapter); + } + }); + + sendTransactionValidator = new SendTransactionValidator(this.getApplicationContext(), this.cryptoNetAccount, etFrom, etTo, etAmount, etMemo); + sendTransactionValidator.setListener(this); + } else { + this.finish(); + } + } + + @OnTextChanged(value = R.id.etFrom, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterFromChanged(Editable editable) { + this.sendTransactionValidator.validate(); + } + + @OnTextChanged(value = R.id.etTo, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterToChanged(Editable editable) { + this.sendTransactionValidator.validate(); + } + + @OnTextChanged(value = R.id.etAmount, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterAmountChanged(Editable editable) { + this.sendTransactionValidator.validate(); + } + + + @OnTextChanged(value = R.id.etMemo, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterMemoChanged(Editable editable) { + this.sendTransactionValidator.validate(); + } + + @OnClick(R.id.btnCancel) + public void cancel(){ + this.finish(); + } + + @OnClick(R.id.btnSend) + public void importSeed(){ + if (this.sendTransactionValidator.isValid()) { + AccountSeed seed = new AccountSeed(); + + //TODO verify if words are already in the db + //TODO check if name has been asigned to other seed + seed.setMasterSeed(etSeedWords.getText().toString()); + seed.setName(etAccountName.getText().toString()); + seed.setType(SeedType.BRAINKEY); + + accountSeedViewModel.addSeed(seed); + + CryptoNetAccountViewModel cryptoNetAccountViewModel = ViewModelProviders.of(this).get(CryptoNetAccountViewModel.class); + GrapheneAccountInfoViewModel grapheneAccountInfoViewModel = ViewModelProviders.of(this).get(GrapheneAccountInfoViewModel.class); + CryptoNetAccount cryptoNetAccount = new CryptoNetAccount(); + cryptoNetAccount.setSeedId(seed.getId()); + cryptoNetAccount.setAccountIndex(0); + cryptoNetAccount.setCryptoNet(CryptoNet.BITSHARES); + cryptoNetAccountViewModel.addCryptoNetAccount(cryptoNetAccount); + GrapheneAccountInfo grapheneAccountInfo = new GrapheneAccountInfo(cryptoNetAccount.getId()); + grapheneAccountInfo.setName(etAccountName.getText().toString()); + grapheneAccountInfoViewModel.addGrapheneAccountInfo(grapheneAccountInfo); + + this.finish(); + } + } + + @Override + public void onValidationSucceeded(final ValidationField field) { + final SendTransactionActivity activity = this; + + activity.runOnUiThread(new Runnable() { + public void run() { + + if (field.getView() == etFrom) { + tvFromError.setText(""); + } else if (field.getView() == etTo){ + tvToError.setText(""); + } else if (field.getView() == etAmount){ + tvAmountError.setText(""); + } else if (field.getView() == etMemo){ + tvMemoError.setText(""); + } + + if (activity.sendTransactionValidator.isValid()){ + btnSend.setEnabled(true); + } else { + btnSend.setEnabled(false); + } + + } + }); + } + + @Override + public void onValidationFailed(ValidationField field) { + if (field.getView() == etFrom) { + tvFromError.setText(field.getMessage()); + } else if (field.getView() == etTo){ + tvToError.setText(field.getMessage()); + } else if (field.getView() == etAmount){ + tvAmountError.setText(field.getMessage()); + } else if (field.getView() == etMemo){ + tvMemoError.setText(field.getMessage()); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java index ce3bd91..973a5c0 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java @@ -28,6 +28,9 @@ public interface CryptoCoinBalanceDao { @Query("SELECT * FROM crypto_coin_balance WHERE account_id = :accountId") LiveData> getBalancesFromAccount(long accountId); + @Query("SELECT * FROM crypto_coin_balance WHERE account_id = :accountId AND crypto_currency_id = :assetId") + CryptoCoinBalance getBalanceFromAccount(long accountId, long assetId); + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertCryptoCoinBalance(CryptoCoinBalance... balances); diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyDao.java index f9c36a6..ae8b2ef 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCurrencyDao.java @@ -22,6 +22,9 @@ public interface CryptoCurrencyDao { @Query("SELECT * FROM crypto_currency WHERE id = :id") CryptoCurrency getById(int id); + @Query("SELECT * FROM crypto_currency WHERE id IN (:ids)") + List getByIds(List ids); + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertCryptoCurrency(CryptoCurrency... currencies); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ImportSeedValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ImportSeedValidator.java index 55f6742..011ff66 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ImportSeedValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ImportSeedValidator.java @@ -3,6 +3,11 @@ package cy.agorise.crystalwallet.viewmodels.validators; import android.content.Context; import android.widget.EditText; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountMnemonicValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountNameValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinConfirmationValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinValidationField; + /** * Created by Henry Varona on 2/10/2017. */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java new file mode 100644 index 0000000..6cd05fb --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java @@ -0,0 +1,36 @@ +package cy.agorise.crystalwallet.viewmodels.validators; + +import android.content.Context; +import android.widget.EditText; +import android.widget.Spinner; + +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.AmountValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.AssetValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.FromValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.MemoValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ToValidationField; + +/** + * Created by Henry Varona on 2/10/2017. + */ + +public class SendTransactionValidator extends UIValidator { + + private CryptoNetAccount account; + + + public SendTransactionValidator(Context context, CryptoNetAccount account, EditText fromEdit, EditText toEdit, Spinner assetSpinner, EditText amountEdit, EditText memoEdit){ + super(context); + this.account = account; + this.addField(new FromValidationField(fromEdit)); + this.addField(new ToValidationField(fromEdit, toEdit)); + this.addField(new AssetValidationField(assetSpinner)); + this.addField(new AmountValidationField(amountEdit, assetSpinner, this.account)); + this.addField(new MemoValidationField(memoEdit)); + } + + public CryptoNetAccount getAccount() { + return account; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidator.java index 9e2a0e3..ae7efb4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidator.java @@ -5,11 +5,13 @@ import android.content.Context; import java.util.ArrayList; import java.util.List; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; + /** * Created by Henry Varona on 7/10/2017. */ -abstract class UIValidator { +public abstract class UIValidator { protected Context context; protected UIValidatorListener listener; protected List validationFields; diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidatorListener.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidatorListener.java index 24a15f0..0719063 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidatorListener.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/UIValidatorListener.java @@ -1,5 +1,7 @@ package cy.agorise.crystalwallet.viewmodels.validators; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; + /** * Created by Henry Varona on 2/10/2017. */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AmountValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AmountValidationField.java new file mode 100644 index 0000000..a5614f4 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AmountValidationField.java @@ -0,0 +1,63 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.view.View; +import android.widget.EditText; +import android.widget.Spinner; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Created by Henry Varona on 7/10/2017. + */ + +public class AmountValidationField extends ValidationField { + + private EditText amountField; + private Spinner assetSpinner; + private CryptoNetAccount account; + + public AmountValidationField(EditText amountField, Spinner assetSpinner, CryptoNetAccount account) { + super(amountField); + this.amountField = amountField; + this.assetSpinner = assetSpinner; + this.account = account; + } + + public void validate(){ + try { + final float newAmountValue = Float.parseFloat(amountField.getText().toString()); + final CryptoCurrency cryptoCurrency = (CryptoCurrency)assetSpinner.getSelectedItem(); + final String mixedValues = newAmountValue+"_"+cryptoCurrency.getId(); + this.setLastValue(mixedValues); + this.startValidating(); + final ValidationField field = this; + + CryptoCoinBalance balance = CrystalDatabase.getAppDatabase(amountField.getContext()).cryptoCoinBalanceDao().getBalanceFromAccount(this.account.getId(),cryptoCurrency.getId()); + + if (newAmountValue > balance.getBalance()){ + setValidForValue(mixedValues, false); + setMessage(validator.getContext().getResources().getString(R.string.insufficient_amount)); + validator.validationFailed(field); + } else if (newAmountValue == 0){ + setValidForValue(mixedValues, false); + setMessage(validator.getContext().getResources().getString(R.string.amount_should_be_greater_than_zero)); + validator.validationFailed(field); + } else { + setValidForValue(mixedValues, true); + validator.validationSucceeded(field); + } + } catch (NumberFormatException e){ + setLastValue(""); + setValidForValue("", false); + setMessage(validator.getContext().getResources().getString(R.string.please_enter_valid_amount)); + validator.validationFailed(this); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AssetValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AssetValidationField.java new file mode 100644 index 0000000..846df03 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AssetValidationField.java @@ -0,0 +1,31 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.widget.EditText; +import android.widget.Spinner; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; +import cy.agorise.crystalwallet.models.CryptoCurrency; + +/** + * Created by Henry Varona on 7/10/2017. + */ + +public class AssetValidationField extends ValidationField { + + private Spinner assetField; + + public AssetValidationField(Spinner assetField){ + super(assetField); + this.assetField = assetField; + } + + public void validate(){ + final CryptoCurrency cryptoCurrencySelected = (CryptoCurrency) this.assetField.getSelectedItem(); + final String newValue = ""+cryptoCurrencySelected.getId(); + this.setLastValue(newValue); + validator.validationSucceeded(this); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountMnemonicValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java similarity index 96% rename from app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountMnemonicValidationField.java rename to app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java index d15fcc0..6150d6f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountMnemonicValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java @@ -1,4 +1,4 @@ -package cy.agorise.crystalwallet.viewmodels.validators; +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; import android.widget.EditText; diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountNameValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java similarity index 90% rename from app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountNameValidationField.java rename to app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java index 5b20359..32ac9ac 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/BitsharesAccountNameValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java @@ -1,13 +1,11 @@ -package cy.agorise.crystalwallet.viewmodels.validators; +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; -import android.content.Context; import android.widget.EditText; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; -import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest; /** * Created by Henry Varona on 7/10/2017. diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/FromValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/FromValidationField.java new file mode 100644 index 0000000..2ca2bfc --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/FromValidationField.java @@ -0,0 +1,45 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.widget.EditText; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; + +/** + * Created by Henry Varona on 7/10/2017. + */ + +public class FromValidationField extends ValidationField { + + private EditText fromField; + + public FromValidationField(EditText fromField){ + super(fromField); + this.fromField = fromField; + } + + public void validate(){ + final String newValue = fromField.getText().toString(); + this.setLastValue(newValue); + this.startValidating(); + final ValidationField field = this; + + final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue); + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (!request.getAccountExists()){ + setValidForValue(newValue, false); + setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); + validator.validationFailed(field); + } else { + setValidForValue(newValue, true); + validator.validationSucceeded(field); + } + } + }); + CryptoNetInfoRequests.getInstance().addRequest(request); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/MemoValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/MemoValidationField.java new file mode 100644 index 0000000..29785bc --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/MemoValidationField.java @@ -0,0 +1,29 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.widget.EditText; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; + +/** + * Created by Henry Varona on 7/10/2017. + */ + +public class MemoValidationField extends ValidationField { + + private EditText memoField; + + public MemoValidationField(EditText memoField){ + super(memoField); + this.memoField = memoField; + } + + public void validate(){ + final String memoNewValue = memoField.getText().toString(); + this.setLastValue(memoNewValue); + setValidForValue(memoNewValue, true); + validator.validationSucceeded(this); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinConfirmationValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java similarity index 93% rename from app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinConfirmationValidationField.java rename to app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java index a319ca1..2087bf7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinConfirmationValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java @@ -1,6 +1,5 @@ -package cy.agorise.crystalwallet.viewmodels.validators; +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; -import android.content.Context; import android.widget.EditText; import cy.agorise.crystalwallet.R; diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java similarity index 85% rename from app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinValidationField.java rename to app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java index e373e4b..cfaf868 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/PinValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java @@ -1,9 +1,9 @@ -package cy.agorise.crystalwallet.viewmodels.validators; +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; -import android.content.Context; import android.widget.EditText; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; /** * Created by Henry Varona on 7/10/2017. diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ToValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ToValidationField.java new file mode 100644 index 0000000..ca2cd8b --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ToValidationField.java @@ -0,0 +1,48 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.widget.EditText; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAccountRequest; + +/** + * Created by Henry Varona on 7/10/2017. + */ + +public class ToValidationField extends ValidationField { + + private EditText fromField; + private EditText toField; + + public ToValidationField(EditText fromField, EditText toField){ + super(fromField); + this.fromField = fromField; + this.toField = toField; + } + + public void validate(){ + final String fromNewValue = fromField.getText().toString(); + final String toNewValue = toField.getText().toString(); + this.setLastValue(toNewValue); + this.startValidating(); + final ValidationField field = this; + + final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (!request.getAccountExists()){ + setValidForValue(toNewValue, false); + setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); + validator.validationFailed(field); + } else { + setValidForValue(toNewValue, true); + validator.validationSucceeded(field); + } + } + }); + CryptoNetInfoRequests.getInstance().addRequest(request); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java similarity index 92% rename from app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ValidationField.java rename to app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java index 933e78b..e624e5e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java @@ -1,8 +1,10 @@ -package cy.agorise.crystalwallet.viewmodels.validators; +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; import android.content.Context; import android.view.View; +import cy.agorise.crystalwallet.viewmodels.validators.UIValidator; + /** * Created by Henry Varona on 2/10/2017. */ diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java new file mode 100644 index 0000000..fc48763 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java @@ -0,0 +1,40 @@ +package cy.agorise.crystalwallet.views; + +import android.content.Context; +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import java.util.List; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCurrency; + +/** + * Created by Henry Varona on 25/10/2017. + */ + +public class CryptoCurrencyAdapter extends ArrayAdapter { + private List data; + + public CryptoCurrencyAdapter(Context context, int resource, List objects) { + super(context, resource, objects); + this.data = objects; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View v = inflater.inflate(R.layout.crypto_currency_adapter_item, parent, false); + TextView tvCryptoCurrencyName = v.findViewById(R.id.tvCryptoCurrencyName); + + CryptoCurrency cryptoCurrency = getItem(position); + tvCryptoCurrencyName.setText(cryptoCurrency.getName()); + + return v; + } +} diff --git a/app/src/main/res/layout/crypto_currency_adapter_item.xml b/app/src/main/res/layout/crypto_currency_adapter_item.xml new file mode 100644 index 0000000..3c64491 --- /dev/null +++ b/app/src/main/res/layout/crypto_currency_adapter_item.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/send_transaction.xml b/app/src/main/res/layout/send_transaction.xml index a7c2ce2..4a46560 100644 --- a/app/src/main/res/layout/send_transaction.xml +++ b/app/src/main/res/layout/send_transaction.xml @@ -2,628 +2,98 @@ - - - - - - - - + - - - - - - - - - + android:layout_height="wrap_content" + android:id="@+id/tvFromError"/> + + + + + + + + + + + + + + \ No newline at end of file