diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java index 26adfa1..e82e88a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java @@ -41,7 +41,7 @@ public class SendTransactionActivity extends AppCompatActivity implements UIVali SendTransactionValidator sendTransactionValidator; @BindView(R.id.spFrom) - MaterialSpinner spFrom; + Spinner spFrom; @BindView(R.id.tvFromError) TextView tvFromError; @BindView(R.id.etTo) diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java index acc1872..dbf3848 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -23,6 +23,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; @@ -35,6 +36,8 @@ import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import butterknife.OnClick; +import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.util.CircularImageView; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; @@ -135,46 +138,13 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali db = CrystalDatabase.getAppDatabase(this.getContext()); this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); - /* - * this is only for graphene accounts. - * - **/ - this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); - this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(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(); - for (CryptoCoinBalance nextBalance : balancesList.getValue()) { - assetIds.add(nextBalance.getCryptoCurrencyId()); - } - List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); - - /* - * Test - * */ - CryptoCurrency crypto1 = new CryptoCurrency(); - crypto1.setId(1); - crypto1.setName("BITCOIN"); - crypto1.setPrecision(1); - cryptoCurrencyList.add(crypto1); - - - CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); - spAsset.setAdapter(assetAdapter); - } - }); - - receiveTransactionValidator = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount); - receiveTransactionValidator.setListener(this); - CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); List cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList(); CryptoNetAccountAdapter toSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts); spTo.setAdapter(toSpinnerAdapter); spTo.setSelection(0); + + setAccountUI(); } builder.setView(view); @@ -247,8 +217,59 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali } } + public void setAccountUI(){ + if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) { + /* + * this is only for graphene accounts. + * + **/ + this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); + this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(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(); + for (CryptoCoinBalance nextBalance : balancesList.getValue()) { + assetIds.add(nextBalance.getCryptoCurrencyId()); + } + List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); + + /* + * Test + * */ + //CryptoCurrency crypto1 = new CryptoCurrency(); + //crypto1.setId(1); + //crypto1.setName("BITCOIN"); + //crypto1.setPrecision(1); + //cryptoCurrencyList.add(crypto1); + + + CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); + spAsset.setAdapter(assetAdapter); + } + }); + + receiveTransactionValidator = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount); + receiveTransactionValidator.setListener(this); + } else { + CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0); + + List currencyList = new ArrayList<>(); + currencyList.add(cryptoCoin.getLabel()); + ArrayAdapter arrayAdapter = new ArrayAdapter(this.getContext(),android.R.layout.simple_list_item_1,currencyList); + spAsset.setAdapter(arrayAdapter); + + receiveTransactionValidator = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount); + receiveTransactionValidator.setListener(this); + } + } + @OnItemSelected(R.id.spTo) public void afterToSelected(Spinner spinner, int position) { + this.cryptoNetAccount = (CryptoNetAccount)spinner.getSelectedItem(); + setAccountUI(); this.receiveTransactionValidator.validate(); } @@ -260,7 +281,10 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali @OnItemSelected(R.id.spAsset) public void afterAssetSelected(Spinner spinner, int position) { - this.cryptoCurrency = (CryptoCurrency)spinner.getSelectedItem(); + if (spinner.getSelectedItem() instanceof CryptoCurrency) { + this.cryptoCurrency = (CryptoCurrency) spinner.getSelectedItem(); + } + this.receiveTransactionValidator.validate(); } 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 767c87f..e3490f4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -32,6 +32,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; @@ -44,6 +45,8 @@ import com.google.zxing.Result; import com.jaredrummler.materialspinner.MaterialSpinner; import com.vincent.filepicker.ToastUtil; +import org.bitcoinj.wallet.SendRequest; + import java.io.File; import java.math.RoundingMode; import java.text.DecimalFormat; @@ -61,7 +64,11 @@ import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; import cy.agorise.crystalwallet.dialogs.material.CrystalDialog; import cy.agorise.crystalwallet.dialogs.material.ToastIt; +import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.interfaces.OnResponse; +import cy.agorise.crystalwallet.requestmanagers.BitcoinSendRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequest; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; @@ -90,7 +97,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat SendTransactionValidator sendTransactionValidator; @BindView(R.id.spFrom) - MaterialSpinner spFrom; + Spinner spFrom; @BindView(R.id.tvFromError) TextView tvFromError; @BindView(R.id.etTo) @@ -195,40 +202,6 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat db = CrystalDatabase.getAppDatabase(this.getContext()); this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); - /* - * this is only for graphene accounts. - * - **/ - this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); - this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(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(); - for (CryptoCoinBalance nextBalance : balancesList.getValue()) { - assetIds.add(nextBalance.getCryptoCurrencyId()); - } - List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); - - /* - * Test - * */ - /*CryptoCurrency crypto1 = new CryptoCurrency(); - crypto1.setId(1); - crypto1.setName("BITCOIN"); - crypto1.setPrecision(1); - cryptoCurrencyList.add(crypto1);*/ - - assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); - spAsset.setAdapter(assetAdapter); - } - }); - // TODO SendTransactionValidator to accept spFrom - 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); @@ -236,30 +209,31 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat /* * If only one account block the control * */ - if(cryptoNetAccounts.size()==1){ - spFrom.setEnabled(false); - } + //if(cryptoNetAccounts.size()==1){ + // spFrom.setEnabled(false); + //} spFrom.setAdapter(fromSpinnerAdapter); - //spFrom.setSelection(0); + spFrom.setSelection(0); + setAccountUI(); /* * Custom material spinner implementation * */ - spFrom.setItems(cryptoNetAccounts); + //spFrom.setItems(cryptoNetAccounts); //spFrom.setSelectedIndex(0); - spFrom.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { - @Override - public void onItemSelected(MaterialSpinner view, int position, long id, CryptoNetAccount item) { - sendTransactionValidator.validate(); - } - }); - spFrom.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { + //spFrom.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { + // @Override + // public void onItemSelected(MaterialSpinner view, int position, long id, CryptoNetAccount item) { + // sendTransactionValidator.validate(); + // } + //}); + //spFrom.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { - @Override public void onNothingSelected(MaterialSpinner spinner) { + // @Override public void onNothingSelected(MaterialSpinner spinner) { - } - }); + // } + //}); // etFrom.setText(this.grapheneAccount.getName()); } @@ -305,6 +279,58 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat return builder.setView(view).create(); } + public void setAccountUI(){ + if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) { + /* + * this is only for graphene accounts. + * + **/ + this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); + this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(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(); + for (CryptoCoinBalance nextBalance : balancesList.getValue()) { + assetIds.add(nextBalance.getCryptoCurrencyId()); + } + List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); + + /* + * Test + * */ + //CryptoCurrency crypto1 = new CryptoCurrency(); + //crypto1.setId(1); + //crypto1.setName("BITCOIN"); + //crypto1.setPrecision(1); + //cryptoCurrencyList.add(crypto1); + + + CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); + spAsset.setAdapter(assetAdapter); + } + }); + + // TODO SendTransactionValidator to accept spFrom + sendTransactionValidator = new SendTransactionValidator(this.getContext(), this.cryptoNetAccount, spFrom, etTo, spAsset, etAmount, etMemo); + sendTransactionValidator.setListener(this); + + } else { + CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0); + + List currencyList = new ArrayList<>(); + currencyList.add(cryptoCoin.getLabel()); + ArrayAdapter arrayAdapter = new ArrayAdapter(this.getContext(),android.R.layout.simple_list_item_1,currencyList); + spAsset.setAdapter(arrayAdapter); + + // TODO SendTransactionValidator to accept spFrom + sendTransactionValidator = new SendTransactionValidator(this.getContext(), this.cryptoNetAccount, spFrom, etTo, spAsset, etAmount, etMemo); + sendTransactionValidator.setListener(this); + + } + } private void requestPermission() { @@ -430,10 +456,12 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } } - /*@OnItemSelected(R.id.spFrom) + @OnItemSelected(R.id.spFrom) public void afterFromSelected(Spinner spinner, int position) { + this.cryptoNetAccount = (CryptoNetAccount)spinner.getSelectedItem(); + setAccountUI(); this.sendTransactionValidator.validate(); - }*/ + } @OnTextChanged(value = R.id.etTo, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) @@ -576,49 +604,85 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat @OnClick(R.id.btnSend) public void sendTransaction(){ final SendTransactionFragment thisFragment = this; + final CryptoNetInfoRequest sendRequest; if (this.sendTransactionValidator.isValid()) { - CryptoNetAccount fromAccountSelected = (CryptoNetAccount) spFrom.getItems().get(spFrom.getSelectedIndex()); + //CryptoNetAccount fromAccountSelected = (CryptoNetAccount) spFrom.getItems().get(spFrom.getSelectedIndex()); + CryptoNetAccount fromAccountSelected = (CryptoNetAccount) spFrom.getSelectedItem(); - /* - * this is only for graphene accounts. - * - **/ - GrapheneAccount grapheneAccountSelected = new GrapheneAccount(fromAccountSelected); - grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(fromAccountSelected.getId())); + if (fromAccountSelected.getCryptoNet() == CryptoNet.BITSHARES) { + /* + * this is only for graphene accounts. + * + **/ + GrapheneAccount grapheneAccountSelected = new GrapheneAccount(fromAccountSelected); + grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(fromAccountSelected.getId())); + //TODO convert the amount to long type using the precision of the currency + Double amountFromEditText = Double.parseDouble(this.etAmount.getText().toString()); + Long amount = (long) Math.floor(amountFromEditText * Math.round(Math.pow(10, ((CryptoCurrency) spAsset.getSelectedItem()).getPrecision()))); - //TODO convert the amount to long type using the precision of the currency - Double amountFromEditText = Double.parseDouble(this.etAmount.getText().toString()); - Long amount = (long)Math.floor(amountFromEditText*Math.round(Math.pow(10,((CryptoCurrency)spAsset.getSelectedItem()).getPrecision()))); + /*final ValidateBitsharesSendRequest*/ + sendRequest = new ValidateBitsharesSendRequest( + this.getContext(), + grapheneAccountSelected, + this.etTo.getText().toString(), + amount, + ((CryptoCurrency) spAsset.getSelectedItem()).getName(), + etMemo.getText().toString() + ); - final ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest( - this.getContext(), - grapheneAccountSelected, - this.etTo.getText().toString(), - amount, - ((CryptoCurrency)spAsset.getSelectedItem()).getName(), - etMemo.getText().toString() - ); - - sendRequest.setListener(new CryptoNetInfoRequestListener() { - @Override - public void onCarryOut() { - if (sendRequest.getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)){ - try { - crystalDialog.dismiss(); - thisFragment.dismiss(); - //thisFragment.finalize(); - } catch (Throwable throwable) { - throwable.printStackTrace(); + sendRequest.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (((ValidateBitsharesSendRequest)sendRequest).getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)) { + try { + crystalDialog.dismiss(); + thisFragment.dismiss(); + //thisFragment.finalize(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } else { + Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG); } - } else { - Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG); } - } - }); + }); + } else { + CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0); + + //TODO convert the amount to long type using the precision of the currency + Double amountFromEditText = Double.parseDouble(this.etAmount.getText().toString()); + Long amount = (long) Math.floor(amountFromEditText * (Math.pow(10, cryptoCoin.getPrecision()))); + + sendRequest = new BitcoinSendRequest( + this.getContext(), + this.cryptoNetAccount, + this.etTo.getText().toString(), + amount, + cryptoCoin, + etMemo.getText().toString() + ); + + sendRequest.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (((BitcoinSendRequest)sendRequest).getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)) { + try { + crystalDialog.dismiss(); + thisFragment.dismiss(); + //thisFragment.finalize(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } else { + Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG); + } + } + }); + } /* * If exists mode scurity show it and valide events in case of success or fail 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 3cd67d9..28e719b 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 @@ -22,7 +22,7 @@ public class SendTransactionValidator extends UIValidator { private CryptoNetAccount account; - public SendTransactionValidator(Context context, CryptoNetAccount account, MaterialSpinner 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/AssetValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/AssetValidationField.java index 15f7688..1216aa4 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 @@ -18,16 +18,22 @@ public class AssetValidationField extends ValidationField { } public void validate(){ - final CryptoCurrency cryptoCurrencySelected = (CryptoCurrency) this.assetField.getSelectedItem(); - if (cryptoCurrencySelected != null) { - final String newValue = "" + cryptoCurrencySelected.getId(); + if (this.assetField.getSelectedItem() instanceof CryptoCurrency) { + final CryptoCurrency cryptoCurrencySelected = (CryptoCurrency) this.assetField.getSelectedItem(); + if (cryptoCurrencySelected != null) { + final String newValue = "" + cryptoCurrencySelected.getId(); + this.setLastValue(newValue); + setValidForValue(newValue, true); + } else { + final String newValue = "" + -1; + setMessageForValue(newValue, "Select a currency"); + this.setLastValue(newValue); + setValidForValue(newValue, false); + } + } else { + final String newValue = "" + -1; this.setLastValue(newValue); setValidForValue(newValue, true); - } else { - final String newValue = ""+-1; - setMessageForValue(newValue,"Select a currency"); - this.setLastValue(newValue); - setValidForValue(newValue, false); } } } 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 4f18033..c857b85 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 @@ -17,9 +17,9 @@ import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountReq public class FromValidationField extends ValidationField { //private EditText fromField; - private MaterialSpinner fromField; + private Spinner fromField; - public FromValidationField(MaterialSpinner fromField){ + public FromValidationField(Spinner fromField){ super(fromField); this.fromField = fromField; } @@ -27,8 +27,8 @@ public class FromValidationField extends ValidationField { public void validate(){ final String newValue; - if (fromField.getSelectedIndex() != -1) { - final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getItems().get(fromField.getSelectedIndex()); + if (fromField.getSelectedItem() instanceof CryptoNetAccount){ + final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getSelectedItem(); newValue = cryptoNetAccount.getName(); } else { newValue = ""; 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 9c06402..18af291 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 @@ -6,6 +6,7 @@ import android.widget.Spinner; import com.jaredrummler.materialspinner.MaterialSpinner; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; @@ -17,10 +18,10 @@ import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountReq public class ToValidationField extends ValidationField { - private MaterialSpinner fromField; + private Spinner fromField; private EditText toField; - public ToValidationField(MaterialSpinner fromField, EditText toField){ + public ToValidationField(Spinner fromField, EditText toField){ super(toField); this.fromField = fromField; this.toField = toField; @@ -28,8 +29,9 @@ public class ToValidationField extends ValidationField { public void validate(){ final String fromNewValue; - if (fromField.getSelectedIndex() != -1) { - final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getItems().get(fromField.getSelectedIndex()); + CryptoNetAccount cryptoNetAccount = null; + if (fromField.getSelectedItem() instanceof CryptoNetAccount){ + cryptoNetAccount = (CryptoNetAccount) fromField.getSelectedItem(); fromNewValue = cryptoNetAccount.getName(); } else { fromNewValue = ""; @@ -45,19 +47,30 @@ public class ToValidationField extends ValidationField { setValidForValue(mixedValue, false); } else { - final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); - request.setListener(new CryptoNetInfoRequestListener() { - @Override - public void onCarryOut() { - if (!request.getAccountExists()) { - setMessageForValue(mixedValue, validator.getContext().getResources().getString(R.string.account_name_not_exist,"'"+toNewValue+"'")); - setValidForValue(mixedValue, false); - } else { + if (cryptoNetAccount != null) { + if (cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) { + final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); + request.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (!request.getAccountExists()) { + setMessageForValue(mixedValue, validator.getContext().getResources().getString(R.string.account_name_not_exist, "'" + toNewValue + "'")); + setValidForValue(mixedValue, false); + } else { + setValidForValue(mixedValue, true); + } + } + }); + CryptoNetInfoRequests.getInstance().addRequest(request); + } else { + //if (addressIsValid(toNewValue)) { setValidForValue(mixedValue, true); - } + //} else { + // setMessageForValue(mixedValue, "Is not a valid address"); + // setValidForValue(mixedValue, false); + //} } - }); - CryptoNetInfoRequests.getInstance().addRequest(request); + } } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java index 9ab9c2b..1917046 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetAccountAdapter.java @@ -6,6 +6,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.ImageView; import android.widget.TextView; import java.util.List; @@ -42,9 +43,11 @@ public class CryptoNetAccountAdapter extends ArrayAdapter { 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); + ImageView ivCryptoNetIcon = v.findViewById(R.id.ivCryptoNetIcon); CryptoNetAccount cryptoNetAccount = getItem(position); tvCryptoNetAccountName.setText(cryptoNetAccount.getName()); + ivCryptoNetIcon.setImageResource(cryptoNetAccount.getCryptoNet().getIconImageResource()); 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 index 5214572..17be0d3 100644 --- a/app/src/main/res/layout/crypto_net_account_adapter_item.xml +++ b/app/src/main/res/layout/crypto_net_account_adapter_item.xml @@ -8,9 +8,27 @@ android:paddingRight="10dp" android:paddingTop="10dp"> - + android:layout_alignParentStart="true" + android:layout_alignParentTop="true"> + + + \ 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 062f47a..921da5e 100644 --- a/app/src/main/res/layout/send_transaction.xml +++ b/app/src/main/res/layout/send_transaction.xml @@ -46,7 +46,8 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - +