From 8a6e8ce24069b5312f27b209849df0eb4acd6679 Mon Sep 17 00:00:00 2001 From: dtvv Date: Wed, 5 Sep 2018 13:20:17 -0500 Subject: [PATCH] In the create seed screen, when all the Fields are complete filled and delete one character in pin field for example, the loading connection server existing account validation was fired --- .../activities/CreateSeedActivity.kt | 67 ++++++++++++++++--- .../BitsharesAccountNameValidation.kt | 48 +++---------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.kt b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.kt index b1b86ba..5eb9400 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.kt +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.kt @@ -13,6 +13,7 @@ import cy.agorise.crystalwallet.R import cy.agorise.crystalwallet.dialogs.material.CrystalDialog import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests import cy.agorise.crystalwallet.requestmanagers.ValidateCreateBitsharesAccountRequest +import cy.agorise.crystalwallet.requestmanagers.ValidateExistBitsharesAccountRequest import cy.agorise.crystalwallet.viewmodels.validators.customImpl.interfaces.UIValidatorListener import cy.agorise.crystalwallet.viewmodels.validators.customImpl.validationFields.BitsharesAccountNameValidation import cy.agorise.crystalwallet.viewmodels.validators.customImpl.validationFields.BitsharesAccountNameValidation.OnAccountExist @@ -62,16 +63,12 @@ class CreateSeedActivity : CustomActivity() { runOnUiThread { val customTextInputEditText = customValidationField.currentView as CustomTextInputEditText customTextInputEditText.error = null + customTextInputEditText.fieldValidatorModel.setValid() } } catch (e: Exception) { e.printStackTrace() } - - /* - * Validate if can continue - * */ - validateFieldsToContinue() } override fun onValidationFailed(customValidationField: CustomValidationField) { @@ -82,6 +79,7 @@ class CreateSeedActivity : CustomActivity() { runOnUiThread { val customTextInputEditText = customValidationField.currentView as CustomTextInputEditText customTextInputEditText.error = customTextInputEditText.fieldValidatorModel.message + customTextInputEditText.fieldValidatorModel.setInvalid() } } } @@ -131,6 +129,8 @@ class CreateSeedActivity : CustomActivity() { * Validate continue to create account * */ validateFieldsToContinue() + + } @OnTextChanged(value = R.id.tietPinConfirmation, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) @@ -148,9 +148,9 @@ class CreateSeedActivity : CustomActivity() { this.fieldsValidator.validate() /* - * Always disable till the server response comes + * Validate continue to create account * */ - disableCreate() + validateFieldsToContinue() } @OnClick(R.id.btnCancel) @@ -221,8 +221,59 @@ class CreateSeedActivity : CustomActivity() { * If the result is true so the user can continue to the creation of the account * */ if (result) { - enableCreate() + + /* + * Show the dialog for connection with the server + * */ + val creatingAccountMaterialDialog = CrystalDialog(globalActivity) + creatingAccountMaterialDialog.setText(globalActivity.resources.getString(R.string.window_create_seed_Server_validation)) + creatingAccountMaterialDialog.progress() + creatingAccountMaterialDialog.show() + + /* + * Validate the account does not exists + * */ + val request = ValidateExistBitsharesAccountRequest(tietAccountName?.text.toString()) + request.setListener { + + /* + * Dismiss the dialog of loading + * */ + creatingAccountMaterialDialog.dismiss() + + if (request.accountExists) { + + /* + * The account exists and is not valid + * */ + tietAccountName.fieldValidatorModel.setInvalid() + tietAccountName.fieldValidatorModel.message = tietAccountName.resources.getString(R.string.account_name_already_exist) + + /* + * Disaible button create + * */ + disableCreate() + + } else { + + /* + * Passed all validations + * */ + tietAccountName.fieldValidatorModel.setValid() + + /* + * Enable button create + * */ + enableCreate() + } + } + CryptoNetInfoRequests.getInstance().addRequest(request) + } else { + + /* + * Disaible button create + * */ disableCreate() } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/customImpl/validationFields/BitsharesAccountNameValidation.kt b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/customImpl/validationFields/BitsharesAccountNameValidation.kt index 9074fcc..2f6f002 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/customImpl/validationFields/BitsharesAccountNameValidation.kt +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/customImpl/validationFields/BitsharesAccountNameValidation.kt @@ -69,6 +69,7 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { * Remove error * */ accountNameField.error = null + accountNameField.fieldValidatorModel.setValid() /* Validate at least min length @@ -87,6 +88,7 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { * Remove error * */ accountNameField.error = null + accountNameField.fieldValidatorModel.setValid() /* Validate at least one character @@ -105,6 +107,7 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { * Remove error * */ accountNameField.error = null + accountNameField.fieldValidatorModel.setValid() /* Validate at least one number for the account string @@ -117,12 +120,14 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { result = false accountNameField.fieldValidatorModel.setInvalid() accountNameField.fieldValidatorModel.message = this.accountNameField.resources.getString(R.string.create_account_window_err_at_least_one_number) + } else { /* * Remove error * */ accountNameField.error = null + accountNameField.fieldValidatorModel.setValid() /* @@ -136,12 +141,14 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { result = false accountNameField.fieldValidatorModel.setInvalid() accountNameField.fieldValidatorModel.message = this.accountNameField.resources.getString(R.string.create_account_window_err_at_least_one_script) + } else { /* * Remove error * */ accountNameField.error = null + accountNameField.fieldValidatorModel.setValid() } } } @@ -162,46 +169,11 @@ class BitsharesAccountNameValidation : CustomValidationField, UIValidator { } else { /* - * Show the dialog for connection with the server + * Deliver result * */ - val creatingAccountMaterialDialog = CrystalDialog(activity) - creatingAccountMaterialDialog.setText(activity.resources.getString(R.string.window_create_seed_Server_validation)) - creatingAccountMaterialDialog.progress() - creatingAccountMaterialDialog.show() - - val request = ValidateExistBitsharesAccountRequest(newValue) - request.setListener { - - /* - * Dismiss the dialog of loading - * */ - creatingAccountMaterialDialog.dismiss() - - if (request.accountExists) { - - /* - * The account exists and is not valid - * */ - accountNameField.fieldValidatorModel.setInvalid() - accountNameField.fieldValidatorModel.message = accountNameField.resources.getString(R.string.account_name_already_exist) - - } else { - - /* - * Passed all validations - * */ - accountNameField.fieldValidatorModel.setValid() - - /* - * Deliver the response - * */ - if (uiValidatorListener != null) { - uiValidatorListener.onValidationSucceeded(globalCustomValidationField) - } - } + if (uiValidatorListener != null) { + uiValidatorListener.onValidationSucceeded(this) } - CryptoNetInfoRequests.getInstance().addRequest(request) - } /* * Passed initial validations, next final validations