- Adjusting import seed validators
This commit is contained in:
parent
5083ad368e
commit
310d4332f7
3 changed files with 48 additions and 21 deletions
|
@ -61,21 +61,23 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
|
|||
@OnTextChanged(value = R.id.etAccountName,
|
||||
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
||||
void afterAccountNameChanged(Editable editable) {
|
||||
this.validator.validateAccountName(editable.getT);
|
||||
this.importSeedValidator.validateAccountName(editable.toString());
|
||||
}
|
||||
|
||||
@OnClick(R.id.btnImport)
|
||||
public void importSeed(){
|
||||
if (this.validator)
|
||||
AccountSeed seed = new AccountSeed();
|
||||
if (this.importSeedValidator.isValid()) {
|
||||
AccountSeed seed = new AccountSeed();
|
||||
|
||||
//TODO verify if PIN and PIN confirmation are not null and are the same
|
||||
//TODO verify if words are already in the db
|
||||
//TODO check if name has been asigned to other seed
|
||||
seed.setMasterSeed(etSeedWords.getText().toString());
|
||||
seed.setName(etAccountName.getText().toString());
|
||||
//TODO verify if PIN and PIN confirmation are not null and are the same
|
||||
//TODO verify if words are already in the db
|
||||
//TODO check if name has been asigned to other seed
|
||||
seed.setMasterSeed(etSeedWords.getText().toString());
|
||||
seed.setName(etAccountName.getText().toString());
|
||||
|
||||
accountSeedViewModel.addSeed(seed);
|
||||
accountSeedViewModel.addSeed(seed);
|
||||
//TODO get back to the previous activity
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cy.agorise.crystalwallet.viewmodels.validators;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -18,13 +19,14 @@ import cy.agorise.crystalwallet.models.AccountSeed;
|
|||
public class ImportSeedValidator {
|
||||
|
||||
private ImportSeedValidatorListener listener;
|
||||
|
||||
private List<ValidationField> validationFields;
|
||||
private AccountSeed accountSeed;
|
||||
private Resources res;
|
||||
|
||||
private boolean isValid = false;
|
||||
|
||||
public ImportSeedValidator(AccountSeed seed){
|
||||
public ImportSeedValidator(Resources res, AccountSeed seed){
|
||||
this.res = res;
|
||||
this.accountSeed = seed;
|
||||
this.validationFields = new ArrayList<ValidationField>();
|
||||
//this.validationFields.add(new ValidationField("pin"));
|
||||
|
@ -36,10 +38,16 @@ public class ImportSeedValidator {
|
|||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void validate(){
|
||||
//validatePin();
|
||||
//validatePinConfirmation();
|
||||
validateAccountName();
|
||||
public boolean isValid(){
|
||||
for(int i=0;i<this.validationFields.size();i++){
|
||||
ValidationField nextField = this.validationFields.get(i);
|
||||
|
||||
if (!nextField.getValid()){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ValidationField getValidationField(String name){
|
||||
|
@ -56,8 +64,9 @@ public class ImportSeedValidator {
|
|||
|
||||
//}
|
||||
|
||||
public void validateAccountName(String accountName){
|
||||
public void validateAccountName(final String accountName){
|
||||
final ValidationField validationField = getValidationField("accountname");
|
||||
validationField.setLastValue(accountName);
|
||||
|
||||
if (this.accountSeed != null){
|
||||
final ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(this.accountSeed.getName(),this.accountSeed.getMasterSeed());
|
||||
|
@ -65,10 +74,10 @@ public class ImportSeedValidator {
|
|||
@Override
|
||||
public void onCarryOut() {
|
||||
if (!request.getAccountExists()){
|
||||
validationField.setValid(false);
|
||||
validationField.setMessage(R.string.account_name_not_exist);
|
||||
validationField.setValidForValue(accountName, false);
|
||||
validationField.setMessage(res.getString(R.string.account_name_not_exist));
|
||||
} else {
|
||||
validationField.setValid(true);
|
||||
validationField.setValidForValue(accountName, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@ package cy.agorise.crystalwallet.viewmodels.validators;
|
|||
public class ValidationField {
|
||||
|
||||
public String name;
|
||||
|
||||
public String lastValue;
|
||||
public String message;
|
||||
public boolean validating;
|
||||
|
@ -32,8 +33,11 @@ public class ValidationField {
|
|||
this.validating = false;
|
||||
}
|
||||
|
||||
public void setValid(boolean newValue){
|
||||
this.valid = newValue;
|
||||
public void setValidForValue(String value, boolean newValue){
|
||||
if (this.lastValue.equals(value)) {
|
||||
this.validating = false;
|
||||
this.valid = newValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMessage(String newValue){
|
||||
|
@ -51,4 +55,16 @@ public class ValidationField {
|
|||
public boolean getValid(){
|
||||
return this.valid;
|
||||
}
|
||||
|
||||
public String getLastValue() {
|
||||
return lastValue;
|
||||
}
|
||||
|
||||
public void setLastValue(String lastValue) {
|
||||
if (!this.lastValue.equals(lastValue)) {
|
||||
this.valid = false;
|
||||
this.validating = false;
|
||||
this.lastValue = lastValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue