From 2f496b0f2adf3814ee9a43d5d2b72f9a4682fcc2 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Sun, 21 Jan 2018 17:20:09 -0400 Subject: [PATCH] - Send Fragment is now working - Fixed validations fields to work only with the last value inserted by the user --- .../2.json | 12 ++- .../activities/BoardActivity.java | 17 ++- .../dao/CryptoCoinBalanceDao.java | 3 + .../dao/CryptoNetAccountDao.java | 3 + .../fragments/SendTransactionFragment.java | 100 ++++++++++++------ .../models/CryptoNetAccount.java | 18 ++++ .../CryptoNetAccountListViewModel.java | 29 +++++ .../CryptoNetBalanceListViewModel.java | 4 + .../validators/SendTransactionValidator.java | 2 +- .../AmountValidationField.java | 10 +- .../AssetValidationField.java | 4 +- ...tsharesAccountMnemonicValidationField.java | 4 +- ...ccountNameDoesntExistsValidationField.java | 6 +- .../BitsharesAccountNameValidationField.java | 4 +- .../validationfields/FromValidationField.java | 19 ++-- .../PinConfirmationValidationField.java | 4 +- .../validationfields/PinValidationField.java | 4 +- .../validationfields/ToValidationField.java | 19 ++-- .../validationfields/ValidationField.java | 16 ++- .../views/CryptoNetAccountAdapter.java | 51 +++++++++ .../crypto_net_account_adapter_item.xml | 16 +++ 21 files changed, 263 insertions(+), 82 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java create mode 100644 app/src/main/res/layout/crypto_net_account_adapter_item.xml diff --git a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json index 26c2578..2f9409f 100644 --- a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json +++ b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 2, - "identityHash": "6a2b148b120a70c3faee581a13c96cf5", + "identityHash": "a44ccb96c8213951403ed2a283fb3367", "entities": [ { "tableName": "account_seed", @@ -44,7 +44,7 @@ }, { "tableName": "crypto_net_account", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `seed_id` INTEGER NOT NULL, `account_index` INTEGER NOT NULL, `crypto_net` TEXT, FOREIGN KEY(`seed_id`) REFERENCES `account_seed`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `seed_id` INTEGER NOT NULL, `account_index` INTEGER NOT NULL, `crypto_net` TEXT, `name` TEXT, FOREIGN KEY(`seed_id`) REFERENCES `account_seed`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )", "fields": [ { "fieldPath": "mId", @@ -69,6 +69,12 @@ "columnName": "crypto_net", "affinity": "TEXT", "notNull": false + }, + { + "fieldPath": "mName", + "columnName": "name", + "affinity": "TEXT", + "notNull": false } ], "primaryKey": { @@ -616,7 +622,7 @@ ], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"6a2b148b120a70c3faee581a13c96cf5\")" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"a44ccb96c8213951403ed2a283fb3367\")" ] } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index 1ee48f5..c857972 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -1,5 +1,7 @@ package cy.agorise.crystalwallet.activities; +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.AnimationDrawable; @@ -24,6 +26,8 @@ import android.view.animation.LinearInterpolator; import android.widget.ImageButton; import android.widget.ImageView; +import java.util.List; + import butterknife.BindColor; import butterknife.BindView; import butterknife.ButterKnife; @@ -35,6 +39,8 @@ import cy.agorise.crystalwallet.fragments.ContactsFragment; import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.fragments.TransactionsFragment; +import cy.agorise.crystalwallet.models.CryptoNetBalance; +import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; /** * Created by Henry Varona on 7/10/2017. @@ -216,8 +222,17 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); + long sendCryptoNetAccountId = -1; + if (this.cryptoNetAccountId != -1){ + sendCryptoNetAccountId = this.cryptoNetAccountId; + } else { + CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class); + sendCryptoNetAccountId = cryptoNetBalanceListViewModel.getFirstBitsharesAccountId(); + } + + // Create and show the dialog. - SendTransactionFragment newFragment = SendTransactionFragment.newInstance(this.cryptoNetAccountId); + SendTransactionFragment newFragment = SendTransactionFragment.newInstance(sendCryptoNetAccountId); newFragment.show(ft, "SendDialog"); } 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 9f698e2..731adfb 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoCoinBalanceDao.java @@ -26,6 +26,9 @@ public interface CryptoCoinBalanceDao { @Query("SELECT id as account_id, crypto_net FROM crypto_net_account") LiveData> getAllBalances(); + @Query("SELECT id FROM crypto_net_account WHERE crypto_net = 'BITSHARES' ORDER BY id ASC LIMIT 1") + long getFirstBitsharesAccountId(); + @Query("SELECT * FROM crypto_coin_balance WHERE account_id = :accountId") LiveData> getBalancesFromAccount(long accountId); diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java index d0eaf66..8875da5 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java @@ -23,6 +23,9 @@ public interface CryptoNetAccountDao { @Query("SELECT * FROM crypto_net_account") LiveData> getAll(); + @Query("SELECT cna.* FROM crypto_net_account cna") + List getAllCryptoNetAccount(); + @Query("SELECT * FROM crypto_net_account WHERE id = :accountId") LiveData getByIdLiveData( long accountId); diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index 8f44adf..270c51c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.fragments; import android.app.Dialog; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; import android.content.DialogInterface; import android.os.Bundle; import android.os.Handler; @@ -36,16 +37,21 @@ import butterknife.OnClick; import butterknife.OnItemSelected; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests; import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.GrapheneAccount; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountViewModel; import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; +import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; import me.dm7.barcodescanner.zxing.ZXingScannerView; public class SendTransactionFragment extends DialogFragment implements UIValidatorListener, ZXingScannerView.ResultHandler { @@ -144,8 +150,15 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } }); // TODO SendTransactionValidator to accept spFrom - //sendTransactionValidator = new SendTransactionValidator(this.getContext(), this.cryptoNetAccount, spFrom, etTo, spAsset, etAmount, etMemo); + sendTransactionValidator = new SendTransactionValidator(this.getContext(), this.cryptoNetAccount, spFrom, etTo, spAsset, etAmount, etMemo); sendTransactionValidator.setListener(this); + + CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); + List cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList(); + CryptoNetAccountAdapter fromSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts); + spFrom.setAdapter(fromSpinnerAdapter); + spFrom.setSelection(0); + // etFrom.setText(this.grapheneAccount.getName()); } @@ -214,11 +227,11 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat this.dismiss(); } - //@OnClick(R.id.btnSend) + @OnClick(R.id.btnSend) public void sendTransaction(){ if (this.sendTransactionValidator.isValid()) { //TODO convert the amount to long type using the precision of the currency - ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest( + final ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest( this.getContext(), this.grapheneAccount, this.etTo.getText().toString(), @@ -227,7 +240,19 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat etMemo.getText().toString() ); - //this.finish(); + sendRequest.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (sendRequest.isSend()){ + try { + this.finalize(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } + } + }); + CryptoNetInfoRequests.getInstance().addRequest(sendRequest); } } @@ -241,41 +266,50 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat public void onValidationSucceeded(final ValidationField field) { final SendTransactionFragment fragment = this; + getActivity().runOnUiThread(new Runnable() { + public void run() { - if (field.getView() == spFrom) { - tvFromError.setText(""); - } else if (field.getView() == etTo){ - tvToError.setText(""); - } else if (field.getView() == etAmount){ - tvAmountError.setText(""); - } else if (field.getView() == spAsset){ - tvAssetError.setText(""); - } else if (field.getView() == etMemo){ - tvMemoError.setText(""); - } + if (field.getView() == spFrom) { + tvFromError.setText(""); + } else if (field.getView() == etTo) { + tvToError.setText(""); + } else if (field.getView() == etAmount) { + tvAmountError.setText(""); + } else if (field.getView() == spAsset) { + tvAssetError.setText(""); + } else if (field.getView() == etMemo) { + tvMemoError.setText(""); + } - if (btnSend != null) { - if (sendTransactionValidator.isValid()) { - btnSend.setEnabled(true); - } else { - btnSend.setEnabled(false); + if (btnSend != null) { + if (sendTransactionValidator.isValid()) { + btnSend.setEnabled(true); + } else { + btnSend.setEnabled(false); + } + } } - } + }); } @Override - public void onValidationFailed(ValidationField field) { - if (field.getView() == spFrom) { - tvFromError.setText(field.getMessage()); - } else if (field.getView() == etTo){ - tvToError.setText(field.getMessage()); - } else if (field.getView() == spAsset){ - tvAssetError.setText(field.getMessage()); - } else if (field.getView() == etAmount){ - tvAmountError.setText(field.getMessage()); - } else if (field.getView() == etMemo){ - tvMemoError.setText(field.getMessage()); - } + public void onValidationFailed(final ValidationField field) { + getActivity().runOnUiThread(new Runnable() { + public void run() { + + if (field.getView() == spFrom) { + tvFromError.setText(field.getMessage()); + } else if (field.getView() == etTo) { + tvToError.setText(field.getMessage()); + } else if (field.getView() == spAsset) { + tvAssetError.setText(field.getMessage()); + } else if (field.getView() == etAmount) { + tvAmountError.setText(field.getMessage()); + } else if (field.getView() == etMemo) { + tvMemoError.setText(field.getMessage()); + } + } + }); } @Override diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java index 421a5aa..6acbc6a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -48,6 +48,12 @@ public class CryptoNetAccount { @ColumnInfo(name = "crypto_net") private CryptoNet mCryptoNet; + /* + * The name of the account + */ + @ColumnInfo(name = "name") + private String mName; + public CryptoNetAccount() { } @@ -90,4 +96,16 @@ public class CryptoNetAccount { public void setCryptoNet(CryptoNet cryptoNet) { this.mCryptoNet = cryptoNet; } + + public String getName() { + return mName; + } + + public void setName(String mName) { + this.mName = mName; + } + + public String toString(){ + return this.getName(); + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java new file mode 100644 index 0000000..8beb01d --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetAccountListViewModel.java @@ -0,0 +1,29 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Created by Henry Varona on 1/21/2018. + */ + +public class CryptoNetAccountListViewModel extends AndroidViewModel { + + private CrystalDatabase db; + + public CryptoNetAccountListViewModel(Application application) { + super(application); + this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); + } + + public List getCryptoNetAccountList(){ + return this.db.cryptoNetAccountDao().getAllCryptoNetAccount(); + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java index 6469f72..b0452a2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java @@ -28,4 +28,8 @@ public class CryptoNetBalanceListViewModel extends AndroidViewModel { public LiveData> getCryptoNetBalanceList(){ return this.cryptoNetBalanceList; } + + public long getFirstBitsharesAccountId(){ + return this.db.cryptoCoinBalanceDao().getFirstBitsharesAccountId(); + } } 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 index 6cd05fb..66565a7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/SendTransactionValidator.java @@ -20,7 +20,7 @@ public class SendTransactionValidator extends UIValidator { private CryptoNetAccount account; - public SendTransactionValidator(Context context, CryptoNetAccount account, EditText fromEdit, EditText toEdit, Spinner assetSpinner, EditText amountEdit, EditText memoEdit){ + public SendTransactionValidator(Context context, CryptoNetAccount account, Spinner fromEdit, EditText toEdit, Spinner assetSpinner, EditText amountEdit, EditText memoEdit){ super(context); this.account = account; this.addField(new FromValidationField(fromEdit)); 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 index a5614f4..1bb7f3e 100644 --- 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 @@ -42,22 +42,18 @@ public class AmountValidationField extends ValidationField { CryptoCoinBalance balance = CrystalDatabase.getAppDatabase(amountField.getContext()).cryptoCoinBalanceDao().getBalanceFromAccount(this.account.getId(),cryptoCurrency.getId()); if (newAmountValue > balance.getBalance()){ + setMessageForValue(mixedValues, validator.getContext().getResources().getString(R.string.insufficient_amount)); setValidForValue(mixedValues, false); - setMessage(validator.getContext().getResources().getString(R.string.insufficient_amount)); - validator.validationFailed(field); } else if (newAmountValue == 0){ + setMessageForValue(mixedValues, validator.getContext().getResources().getString(R.string.amount_should_be_greater_than_zero)); 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(""); + setMessageForValue("",validator.getContext().getResources().getString(R.string.please_enter_valid_amount)); 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 index 54691f7..b359d8c 100644 --- 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 @@ -28,13 +28,11 @@ public class AssetValidationField extends ValidationField { final String newValue = "" + cryptoCurrencySelected.getId(); this.setLastValue(newValue); setValidForValue(newValue, true); - validator.validationSucceeded(this); } else { final String newValue = ""+-1; - setMessage("Select a currency"); + setMessageForValue(newValue,"Select a currency"); this.setLastValue(newValue); setValidForValue(newValue, false); - validator.validationFailed(this); } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java index 6150d6f..02f99a8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountMnemonicValidationField.java @@ -36,12 +36,10 @@ public class BitsharesAccountMnemonicValidationField extends ValidationField { @Override public void onCarryOut() { if (!request.getMnemonicIsCorrect()){ + setMessageForValue(mixedValue,validator.getContext().getResources().getString(R.string.error_invalid_account)); setValidForValue(mixedValue, false); - setMessage(validator.getContext().getResources().getString(R.string.error_invalid_account)); - validator.validationFailed(field); } else { setValidForValue(mixedValue, true); - validator.validationSucceeded(field); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java index 79c965a..6660201 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameDoesntExistsValidationField.java @@ -27,7 +27,7 @@ public class BitsharesAccountNameDoesntExistsValidationField extends ValidationF if (newValue.equals("")){ setValidForValue("", false); - setMessage(""); + setMessageForValue("",""); validator.validationFailed(this); } else { @@ -38,12 +38,10 @@ public class BitsharesAccountNameDoesntExistsValidationField extends ValidationF @Override public void onCarryOut() { if (request.getAccountExists()) { + setMessageForValue(newValue,validator.getContext().getResources().getString(R.string.account_name_already_exist,"'"+newValue+"'")); setValidForValue(newValue, false); - setMessage(validator.getContext().getResources().getString(R.string.account_name_already_exist,"'"+newValue+"'")); - validator.validationFailed(field); } else { setValidForValue(newValue, true); - validator.validationSucceeded(field); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java index 32ac9ac..60c4db6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/BitsharesAccountNameValidationField.java @@ -31,12 +31,10 @@ public class BitsharesAccountNameValidationField extends ValidationField { @Override public void onCarryOut() { if (!request.getAccountExists()){ + setMessageForValue(newValue,validator.getContext().getResources().getString(R.string.account_name_not_exist)); setValidForValue(newValue, false); - setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); - validator.validationFailed(field); } else { setValidForValue(newValue, true); - validator.validationSucceeded(field); } } }); 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 index 2ca2bfc..fe32c7c 100644 --- 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 @@ -1,6 +1,7 @@ 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; @@ -13,15 +14,23 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAcco public class FromValidationField extends ValidationField { - private EditText fromField; + //private EditText fromField; + private Spinner fromField; - public FromValidationField(EditText fromField){ + public FromValidationField(Spinner fromField){ super(fromField); this.fromField = fromField; } public void validate(){ - final String newValue = fromField.getText().toString(); + final String newValue; + + if (fromField.getSelectedItem() != null) { + newValue = fromField.getSelectedItem().toString(); + } else { + newValue = ""; + } + this.setLastValue(newValue); this.startValidating(); final ValidationField field = this; @@ -31,12 +40,10 @@ public class FromValidationField extends ValidationField { @Override public void onCarryOut() { if (!request.getAccountExists()){ + setMessageForValue(newValue,validator.getContext().getResources().getString(R.string.account_name_not_exist, "'"+newValue+"'")); setValidForValue(newValue, false); - setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); - validator.validationFailed(field); } else { setValidForValue(newValue, true); - validator.validationSucceeded(field); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java index 2087bf7..00f951e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinConfirmationValidationField.java @@ -29,12 +29,10 @@ public class PinConfirmationValidationField extends ValidationField { if (!newConfirmationValue.equals(newValue)){ + this.setMessageForValue(mixedValue,this.validator.getContext().getResources().getString(R.string.mismatch_pin)); this.setValidForValue(mixedValue,false); - this.setMessage(this.validator.getContext().getResources().getString(R.string.mismatch_pin)); - this.validator.validationFailed(this); } else { this.setValidForValue(mixedValue, true); - this.validator.validationSucceeded(this); } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java index cfaf868..809b8c6 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/PinValidationField.java @@ -25,12 +25,10 @@ public class PinValidationField extends ValidationField { this.startValidating(); if (newValue.length() < 6) { + this.setMessageForValue(newValue, this.validator.getContext().getResources().getString(R.string.pin_number_warning)); this.setValidForValue(newValue, false); - this.setMessage(this.validator.getContext().getResources().getString(R.string.pin_number_warning)); - this.validator.validationFailed(this); } else { this.setValidForValue(newValue, true); - this.validator.validationSucceeded(this); } } } 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 index f8b676c..12d7e93 100644 --- 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 @@ -1,6 +1,7 @@ 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; @@ -13,17 +14,22 @@ import cy.agorise.crystalwallet.cryptonetinforequests.ValidateExistBitsharesAcco public class ToValidationField extends ValidationField { - private EditText fromField; + private Spinner fromField; private EditText toField; - public ToValidationField(EditText fromField, EditText toField){ + public ToValidationField(Spinner fromField, EditText toField){ super(toField); this.fromField = fromField; this.toField = toField; } public void validate(){ - final String fromNewValue = fromField.getText().toString(); + final String fromNewValue; + if (fromField.getSelectedItem() != null) { + fromNewValue = fromField.getSelectedItem().toString(); + } else { + fromNewValue = ""; + } final String toNewValue = toField.getText().toString(); final String mixedValue = fromNewValue+"_"+toNewValue; this.setLastValue(mixedValue); @@ -31,9 +37,8 @@ public class ToValidationField extends ValidationField { final ValidationField field = this; if (fromNewValue.equals(toNewValue)){ + setMessageForValue(mixedValue,validator.getContext().getResources().getString(R.string.warning_msg_same_account)); setValidForValue(mixedValue, false); - setMessage(validator.getContext().getResources().getString(R.string.warning_msg_same_account)); - validator.validationFailed(field); } else { final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); @@ -41,12 +46,10 @@ public class ToValidationField extends ValidationField { @Override public void onCarryOut() { if (!request.getAccountExists()) { + setMessageForValue(mixedValue, validator.getContext().getResources().getString(R.string.account_name_not_exist,"'"+toNewValue+"'")); setValidForValue(mixedValue, false); - setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); - validator.validationFailed(field); } else { setValidForValue(mixedValue, true); - validator.validationSucceeded(field); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java index e624e5e..0884c19 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/ValidationField.java @@ -41,15 +41,23 @@ public abstract class ValidationField { this.validating = false; } - public void setValidForValue(String value, boolean newValue){ + public void setValidForValue(String value, boolean isValid){ if (this.lastValue.equals(value)) { this.validating = false; - this.valid = newValue; + this.valid = isValid; + + if (isValid) { + validator.validationSucceeded(this); + } else { + validator.validationFailed(this); + } } } - public void setMessage(String newValue){ - this.message = newValue; + public void setMessageForValue(String value, String message){ + if (this.lastValue.equals(value)) { + this.message = message; + } } public String getMessage(){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java new file mode 100644 index 0000000..9ab9c2b --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java @@ -0,0 +1,51 @@ +package cy.agorise.crystalwallet.views; + +import android.arch.lifecycle.ViewModelProviders; +import android.content.Context; +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; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; + +/** + * Created by Henry Varona on 01/20/2018. + * + * The adapter to show a list of crypto net account in a spinner. + */ + +public class CryptoNetAccountAdapter extends ArrayAdapter { + private List data; + + public CryptoNetAccountAdapter(Context context, int resource, List objects) { + super(context, resource, objects); + this.data = objects; + } + + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + return getView(position, convertView, parent); + } + + /* + * Creates the view for every element of the spinner + */ + @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_net_account_adapter_item, parent, false); + TextView tvCryptoNetAccountName = v.findViewById(R.id.tvCryptoNetAccountName); + + CryptoNetAccount cryptoNetAccount = getItem(position); + tvCryptoNetAccountName.setText(cryptoNetAccount.getName()); + + return v; + } +} diff --git a/app/src/main/res/layout/crypto_net_account_adapter_item.xml b/app/src/main/res/layout/crypto_net_account_adapter_item.xml new file mode 100644 index 0000000..5214572 --- /dev/null +++ b/app/src/main/res/layout/crypto_net_account_adapter_item.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file