2017-10-26 01:33:38 +00:00
|
|
|
package cy.agorise.crystalwallet.viewmodels.validators.validationfields;
|
2017-10-08 03:03:59 +00:00
|
|
|
|
2018-01-21 21:20:09 +00:00
|
|
|
import android.widget.Spinner;
|
2017-10-08 03:03:59 +00:00
|
|
|
|
|
|
|
import cy.agorise.crystalwallet.R;
|
2018-03-28 01:44:41 +00:00
|
|
|
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener;
|
|
|
|
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
|
|
|
|
import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountRequest;
|
2017-10-08 03:03:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Henry Varona on 7/10/2017.
|
|
|
|
*/
|
|
|
|
|
2017-10-26 01:33:38 +00:00
|
|
|
public class FromValidationField extends ValidationField {
|
2017-10-08 03:03:59 +00:00
|
|
|
|
2018-01-21 21:20:09 +00:00
|
|
|
//private EditText fromField;
|
|
|
|
private Spinner fromField;
|
2017-10-08 03:03:59 +00:00
|
|
|
|
2018-01-21 21:20:09 +00:00
|
|
|
public FromValidationField(Spinner fromField){
|
2017-10-26 01:33:38 +00:00
|
|
|
super(fromField);
|
|
|
|
this.fromField = fromField;
|
2017-10-08 03:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void validate(){
|
2018-01-21 21:20:09 +00:00
|
|
|
final String newValue;
|
|
|
|
|
|
|
|
if (fromField.getSelectedItem() != null) {
|
|
|
|
newValue = fromField.getSelectedItem().toString();
|
|
|
|
} else {
|
|
|
|
newValue = "";
|
|
|
|
}
|
|
|
|
|
2017-10-08 03:03:59 +00:00
|
|
|
this.setLastValue(newValue);
|
|
|
|
this.startValidating();
|
|
|
|
final ValidationField field = this;
|
|
|
|
|
2017-10-10 02:45:48 +00:00
|
|
|
final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(newValue);
|
2017-10-08 03:03:59 +00:00
|
|
|
request.setListener(new CryptoNetInfoRequestListener() {
|
|
|
|
@Override
|
|
|
|
public void onCarryOut() {
|
|
|
|
if (!request.getAccountExists()){
|
2018-01-21 21:20:09 +00:00
|
|
|
setMessageForValue(newValue,validator.getContext().getResources().getString(R.string.account_name_not_exist, "'"+newValue+"'"));
|
2017-10-08 03:03:59 +00:00
|
|
|
setValidForValue(newValue, false);
|
|
|
|
} else {
|
|
|
|
setValidForValue(newValue, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
CryptoNetInfoRequests.getInstance().addRequest(request);
|
|
|
|
}
|
|
|
|
}
|