- ReceiveFragment and SendFragmente were adapted to manage bitcoin accounts

This commit is contained in:
Javier Varona 2018-11-07 22:02:15 -04:00
parent e9f77c4981
commit 9df1db6669
10 changed files with 284 additions and 155 deletions

View file

@ -41,7 +41,7 @@ public class SendTransactionActivity extends AppCompatActivity implements UIVali
SendTransactionValidator sendTransactionValidator; SendTransactionValidator sendTransactionValidator;
@BindView(R.id.spFrom) @BindView(R.id.spFrom)
MaterialSpinner spFrom; Spinner spFrom;
@BindView(R.id.tvFromError) @BindView(R.id.tvFromError)
TextView tvFromError; TextView tvFromError;
@BindView(R.id.etTo) @BindView(R.id.etTo)

View file

@ -23,6 +23,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
@ -35,6 +36,8 @@ import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import butterknife.OnClick; 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.util.CircularImageView;
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel;
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
@ -135,46 +138,13 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
db = CrystalDatabase.getAppDatabase(this.getContext()); db = CrystalDatabase.getAppDatabase(this.getContext());
this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); 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<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> 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); CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class);
List<CryptoNetAccount> cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList(); List<CryptoNetAccount> cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList();
CryptoNetAccountAdapter toSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts); CryptoNetAccountAdapter toSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts);
spTo.setAdapter(toSpinnerAdapter); spTo.setAdapter(toSpinnerAdapter);
spTo.setSelection(0); spTo.setSelection(0);
setAccountUI();
} }
builder.setView(view); 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<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> 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<String> currencyList = new ArrayList<>();
currencyList.add(cryptoCoin.getLabel());
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(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) @OnItemSelected(R.id.spTo)
public void afterToSelected(Spinner spinner, int position) { public void afterToSelected(Spinner spinner, int position) {
this.cryptoNetAccount = (CryptoNetAccount)spinner.getSelectedItem();
setAccountUI();
this.receiveTransactionValidator.validate(); this.receiveTransactionValidator.validate();
} }
@ -260,7 +281,10 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
@OnItemSelected(R.id.spAsset) @OnItemSelected(R.id.spAsset)
public void afterAssetSelected(Spinner spinner, int position) { 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(); this.receiveTransactionValidator.validate();
} }

View file

@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.Window; import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
@ -44,6 +45,8 @@ import com.google.zxing.Result;
import com.jaredrummler.materialspinner.MaterialSpinner; import com.jaredrummler.materialspinner.MaterialSpinner;
import com.vincent.filepicker.ToastUtil; import com.vincent.filepicker.ToastUtil;
import org.bitcoinj.wallet.SendRequest;
import java.io.File; import java.io.File;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -61,7 +64,11 @@ import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
import cy.agorise.crystalwallet.dialogs.material.CrystalDialog; import cy.agorise.crystalwallet.dialogs.material.CrystalDialog;
import cy.agorise.crystalwallet.dialogs.material.ToastIt; 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.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.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest;
@ -90,7 +97,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
SendTransactionValidator sendTransactionValidator; SendTransactionValidator sendTransactionValidator;
@BindView(R.id.spFrom) @BindView(R.id.spFrom)
MaterialSpinner spFrom; Spinner spFrom;
@BindView(R.id.tvFromError) @BindView(R.id.tvFromError)
TextView tvFromError; TextView tvFromError;
@BindView(R.id.etTo) @BindView(R.id.etTo)
@ -195,40 +202,6 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
db = CrystalDatabase.getAppDatabase(this.getContext()); db = CrystalDatabase.getAppDatabase(this.getContext());
this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); 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<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> 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); CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class);
List<CryptoNetAccount> cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList(); List<CryptoNetAccount> cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList();
CryptoNetAccountAdapter fromSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts); 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 only one account block the control
* */ * */
if(cryptoNetAccounts.size()==1){ //if(cryptoNetAccounts.size()==1){
spFrom.setEnabled(false); // spFrom.setEnabled(false);
} //}
spFrom.setAdapter(fromSpinnerAdapter); spFrom.setAdapter(fromSpinnerAdapter);
//spFrom.setSelection(0); spFrom.setSelection(0);
setAccountUI();
/* /*
* Custom material spinner implementation * Custom material spinner implementation
* */ * */
spFrom.setItems(cryptoNetAccounts); //spFrom.setItems(cryptoNetAccounts);
//spFrom.setSelectedIndex(0); //spFrom.setSelectedIndex(0);
spFrom.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<CryptoNetAccount>() { //spFrom.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<CryptoNetAccount>() {
@Override // @Override
public void onItemSelected(MaterialSpinner view, int position, long id, CryptoNetAccount item) { // public void onItemSelected(MaterialSpinner view, int position, long id, CryptoNetAccount item) {
sendTransactionValidator.validate(); // sendTransactionValidator.validate();
} // }
}); //});
spFrom.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() { //spFrom.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {
@Override public void onNothingSelected(MaterialSpinner spinner) { // @Override public void onNothingSelected(MaterialSpinner spinner) {
} // }
}); //});
// etFrom.setText(this.grapheneAccount.getName()); // etFrom.setText(this.grapheneAccount.getName());
} }
@ -305,6 +279,58 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
return builder.setView(view).create(); 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<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> 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<String> currencyList = new ArrayList<>();
currencyList.add(cryptoCoin.getLabel());
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(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() { 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) { public void afterFromSelected(Spinner spinner, int position) {
this.cryptoNetAccount = (CryptoNetAccount)spinner.getSelectedItem();
setAccountUI();
this.sendTransactionValidator.validate(); this.sendTransactionValidator.validate();
}*/ }
@OnTextChanged(value = R.id.etTo, @OnTextChanged(value = R.id.etTo,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
@ -576,49 +604,85 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
@OnClick(R.id.btnSend) @OnClick(R.id.btnSend)
public void sendTransaction(){ public void sendTransaction(){
final SendTransactionFragment thisFragment = this; final SendTransactionFragment thisFragment = this;
final CryptoNetInfoRequest sendRequest;
if (this.sendTransactionValidator.isValid()) { 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();
/* if (fromAccountSelected.getCryptoNet() == CryptoNet.BITSHARES) {
* this is only for graphene accounts. /*
* * this is only for graphene accounts.
**/ *
GrapheneAccount grapheneAccountSelected = new GrapheneAccount(fromAccountSelected); **/
grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(fromAccountSelected.getId())); 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 /*final ValidateBitsharesSendRequest*/
Double amountFromEditText = Double.parseDouble(this.etAmount.getText().toString()); sendRequest = new ValidateBitsharesSendRequest(
Long amount = (long)Math.floor(amountFromEditText*Math.round(Math.pow(10,((CryptoCurrency)spAsset.getSelectedItem()).getPrecision()))); this.getContext(),
grapheneAccountSelected,
this.etTo.getText().toString(),
amount,
((CryptoCurrency) spAsset.getSelectedItem()).getName(),
etMemo.getText().toString()
);
final ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest( sendRequest.setListener(new CryptoNetInfoRequestListener() {
this.getContext(), @Override
grapheneAccountSelected, public void onCarryOut() {
this.etTo.getText().toString(), if (((ValidateBitsharesSendRequest)sendRequest).getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)) {
amount, try {
((CryptoCurrency)spAsset.getSelectedItem()).getName(), crystalDialog.dismiss();
etMemo.getText().toString() thisFragment.dismiss();
); //thisFragment.finalize();
} catch (Throwable throwable) {
sendRequest.setListener(new CryptoNetInfoRequestListener() { throwable.printStackTrace();
@Override }
public void onCarryOut() { } else {
if (sendRequest.getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)){ Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG);
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 {
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 * If exists mode scurity show it and valide events in case of success or fail

View file

@ -22,7 +22,7 @@ public class SendTransactionValidator extends UIValidator {
private CryptoNetAccount account; 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); super(context);
this.account = account; this.account = account;
this.addField(new FromValidationField(fromEdit)); this.addField(new FromValidationField(fromEdit));

View file

@ -18,16 +18,22 @@ public class AssetValidationField extends ValidationField {
} }
public void validate(){ public void validate(){
final CryptoCurrency cryptoCurrencySelected = (CryptoCurrency) this.assetField.getSelectedItem(); if (this.assetField.getSelectedItem() instanceof CryptoCurrency) {
if (cryptoCurrencySelected != null) { final CryptoCurrency cryptoCurrencySelected = (CryptoCurrency) this.assetField.getSelectedItem();
final String newValue = "" + cryptoCurrencySelected.getId(); 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); this.setLastValue(newValue);
setValidForValue(newValue, true); setValidForValue(newValue, true);
} else {
final String newValue = ""+-1;
setMessageForValue(newValue,"Select a currency");
this.setLastValue(newValue);
setValidForValue(newValue, false);
} }
} }
} }

View file

@ -17,9 +17,9 @@ import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountReq
public class FromValidationField extends ValidationField { public class FromValidationField extends ValidationField {
//private EditText fromField; //private EditText fromField;
private MaterialSpinner fromField; private Spinner fromField;
public FromValidationField(MaterialSpinner fromField){ public FromValidationField(Spinner fromField){
super(fromField); super(fromField);
this.fromField = fromField; this.fromField = fromField;
} }
@ -27,8 +27,8 @@ public class FromValidationField extends ValidationField {
public void validate(){ public void validate(){
final String newValue; final String newValue;
if (fromField.getSelectedIndex() != -1) { if (fromField.getSelectedItem() instanceof CryptoNetAccount){
final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getItems().get(fromField.getSelectedIndex()); final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getSelectedItem();
newValue = cryptoNetAccount.getName(); newValue = cryptoNetAccount.getName();
} else { } else {
newValue = ""; newValue = "";

View file

@ -6,6 +6,7 @@ import android.widget.Spinner;
import com.jaredrummler.materialspinner.MaterialSpinner; import com.jaredrummler.materialspinner.MaterialSpinner;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
@ -17,10 +18,10 @@ import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountReq
public class ToValidationField extends ValidationField { public class ToValidationField extends ValidationField {
private MaterialSpinner fromField; private Spinner fromField;
private EditText toField; private EditText toField;
public ToValidationField(MaterialSpinner fromField, EditText toField){ public ToValidationField(Spinner fromField, EditText toField){
super(toField); super(toField);
this.fromField = fromField; this.fromField = fromField;
this.toField = toField; this.toField = toField;
@ -28,8 +29,9 @@ public class ToValidationField extends ValidationField {
public void validate(){ public void validate(){
final String fromNewValue; final String fromNewValue;
if (fromField.getSelectedIndex() != -1) { CryptoNetAccount cryptoNetAccount = null;
final CryptoNetAccount cryptoNetAccount = (CryptoNetAccount) fromField.getItems().get(fromField.getSelectedIndex()); if (fromField.getSelectedItem() instanceof CryptoNetAccount){
cryptoNetAccount = (CryptoNetAccount) fromField.getSelectedItem();
fromNewValue = cryptoNetAccount.getName(); fromNewValue = cryptoNetAccount.getName();
} else { } else {
fromNewValue = ""; fromNewValue = "";
@ -45,19 +47,30 @@ public class ToValidationField extends ValidationField {
setValidForValue(mixedValue, false); setValidForValue(mixedValue, false);
} else { } else {
final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); if (cryptoNetAccount != null) {
request.setListener(new CryptoNetInfoRequestListener() { if (cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) {
@Override final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue);
public void onCarryOut() { request.setListener(new CryptoNetInfoRequestListener() {
if (!request.getAccountExists()) { @Override
setMessageForValue(mixedValue, validator.getContext().getResources().getString(R.string.account_name_not_exist,"'"+toNewValue+"'")); public void onCarryOut() {
setValidForValue(mixedValue, false); if (!request.getAccountExists()) {
} else { 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); setValidForValue(mixedValue, true);
} //} else {
// setMessageForValue(mixedValue, "Is not a valid address");
// setValidForValue(mixedValue, false);
//}
} }
}); }
CryptoNetInfoRequests.getInstance().addRequest(request);
} }
} }
} }

View file

@ -6,6 +6,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.List; import java.util.List;
@ -42,9 +43,11 @@ public class CryptoNetAccountAdapter extends ArrayAdapter<CryptoNetAccount> {
LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.crypto_net_account_adapter_item, parent, false); View v = inflater.inflate(R.layout.crypto_net_account_adapter_item, parent, false);
TextView tvCryptoNetAccountName = v.findViewById(R.id.tvCryptoNetAccountName); TextView tvCryptoNetAccountName = v.findViewById(R.id.tvCryptoNetAccountName);
ImageView ivCryptoNetIcon = v.findViewById(R.id.ivCryptoNetIcon);
CryptoNetAccount cryptoNetAccount = getItem(position); CryptoNetAccount cryptoNetAccount = getItem(position);
tvCryptoNetAccountName.setText(cryptoNetAccount.getName()); tvCryptoNetAccountName.setText(cryptoNetAccount.getName());
ivCryptoNetIcon.setImageResource(cryptoNetAccount.getCryptoNet().getIconImageResource());
return v; return v;
} }

View file

@ -8,9 +8,27 @@
android:paddingRight="10dp" android:paddingRight="10dp"
android:paddingTop="10dp"> android:paddingTop="10dp">
<TextView <RelativeLayout
android:id="@+id/tvCryptoNetAccountName" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="10" /> android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:id="@+id/ivCryptoNetIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxHeight="28dp"
android:maxWidth="28dp"
app:srcCompat="@drawable/bts" />
<TextView
android:id="@+id/tvCryptoNetAccountName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@id/ivCryptoNetIcon"
android:ems="10"
android:text="unknown coin" />
</RelativeLayout>
</LinearLayout> </LinearLayout>

View file

@ -46,7 +46,8 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<com.jaredrummler.materialspinner.MaterialSpinner <!--<com.jaredrummler.materialspinner.MaterialSpinner-->
<Spinner
android:id="@+id/spFrom" android:id="@+id/spFrom"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="40dp" android:layout_height="40dp"