From 1545f0e10bd626c3a6cc722db1f9cc9595f7ccca Mon Sep 17 00:00:00 2001 From: dtvv Date: Thu, 4 Oct 2018 10:15:58 -0500 Subject: [PATCH] =?UTF-8?q?When=20you=20try=20to=20import=20your=20account?= =?UTF-8?q?=20from=20seed,=20the=20button=20=E2=80=9CCREATE=20WALLET?= =?UTF-8?q?=E2=80=9D=20should=20be=20disabled=20till=20all=20the=20fields?= =?UTF-8?q?=20are=20correctly=20filled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activities/ImportSeedActivity.java | 158 +++++++++++++++++- 1 file changed, 155 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java index c583459..a95890b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/ImportSeedActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.Editable; +import android.text.TextWatcher; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; @@ -60,12 +61,136 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator ButterKnife.bind(this); - btnImport.setEnabled(false); + /* + * Initially the button CREATE WALLET should be disabled + * */ + disableCreate(); + + /* + * When a text change in any of the fields + * */ + etPin.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + + /* + * If all is ready to continue enable the button, contrarie case disable it + * */ + if(allFieldsAreFill()){ + enableCreate(); + } + else{ + disableCreate(); + } + } + }); + etPinConfirmation.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + + /* + * If all is ready to continue enable the button, contrarie case disable it + * */ + if(allFieldsAreFill()){ + enableCreate(); + } + else{ + disableCreate(); + } + } + }); + etSeedWords.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + + /* + * If all is ready to continue enable the button, contrarie case disable it + * */ + if(allFieldsAreFill()){ + enableCreate(); + } + else{ + disableCreate(); + } + } + }); + etAccountName.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + + /* + * If all is ready to continue enable the button, contrarie case disable it + * */ + if(allFieldsAreFill()){ + enableCreate(); + } + else{ + disableCreate(); + } + } + }); + accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); importSeedValidator = new ImportSeedValidator(this.getApplicationContext(),etPin,etPinConfirmation,etAccountName,etSeedWords); importSeedValidator.setListener(this); } + + /* + * Method to validate if all the fields are fill + * */ + private boolean allFieldsAreFill(){ + + boolean complete = false; + if( etPin.getText().toString().trim().compareTo("")!=0 && + etPinConfirmation.getText().toString().trim().compareTo("")!=0 && + etSeedWords.getText().toString().trim().compareTo("")!=0 && + etAccountName.getText().toString().trim().compareTo("")!=0){ + complete = true; + } + return complete; + } + @OnTextChanged(value = R.id.etPin, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterPinChanged(Editable editable) { @@ -182,9 +307,9 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator } if (activity.importSeedValidator.isValid()){ - btnImport.setEnabled(true); + enableCreate(); } else { - btnImport.setEnabled(false); + disableCreate(); } } @@ -203,4 +328,31 @@ public class ImportSeedActivity extends AppCompatActivity implements UIValidator //tvSeedWordsError.setText(field.getMessage()); } } + + + /* + * Enable create button + * */ + private void enableCreate() { + runOnUiThread(new Runnable() { + @Override + public void run() { + btnImport.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); + btnImport.setEnabled(true); + } + }); + } + + /* + * Disable create button + * */ + private void disableCreate() { + runOnUiThread(new Runnable() { + @Override + public void run() { + btnImport.setEnabled(false); + btnImport.setBackground(getDrawable(R.drawable.disable_style)); + } + }); + } }