From 013a3b841fe5f4eb292047d838bcba0d1e87c928 Mon Sep 17 00:00:00 2001 From: dtvv Date: Sun, 14 Oct 2018 01:57:41 -0500 Subject: [PATCH] -When the PIN is being entered the user should press a button to confirm the pin -When the PIN is being entered use question dialog to confirm the save PIN -When the PIN is correcto typed and match correctly enable the ok button --- .../fragments/PinSecurityFragment.java | 86 +++++++++++++++++-- .../main/res/layout/fragment_pin_security.xml | 11 +++ app/src/main/res/values/strings.xml | 2 + 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/PinSecurityFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/PinSecurityFragment.java index c5d298c..8603607 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/PinSecurityFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/PinSecurityFragment.java @@ -8,17 +8,25 @@ import android.text.Editable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; +import org.jetbrains.annotations.NotNull; + import java.util.List; import butterknife.BindView; import butterknife.ButterKnife; +import butterknife.OnClick; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.application.CrystalSecurityMonitor; +import cy.agorise.crystalwallet.dialogs.material.DialogMaterial; +import cy.agorise.crystalwallet.dialogs.material.NegativeResponse; +import cy.agorise.crystalwallet.dialogs.material.PositiveResponse; +import cy.agorise.crystalwallet.dialogs.material.QuestionDialog; import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.util.PasswordManager; import cy.agorise.crystalwallet.viewmodels.GeneralSettingListViewModel; @@ -42,6 +50,14 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener @BindView(R.id.tvConfirmPinError) TextView tvConfirmPinError; + @BindView(R.id.btnOK) + Button btnOK; + + /* + * Flag to check if validation of fields is correct + * */ + private boolean valid = false; + GeneralSettingListViewModel generalSettingListViewModel; GeneralSetting passwordGeneralSetting; PinSecurityValidator pinSecurityValidator; @@ -64,6 +80,11 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener View v = inflater.inflate(R.layout.fragment_pin_security, container, false); ButterKnife.bind(this, v); + /* + * Initially not enabled til it passes validations + * */ + btnOK.setEnabled(false); + generalSettingListViewModel = ViewModelProviders.of(this).get(GeneralSettingListViewModel.class); LiveData> generalSettingsLiveData = generalSettingListViewModel.getGeneralSettingList(); @@ -73,6 +94,35 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener return v; } + + @OnClick(R.id.btnOK) + void okClic(final View view) { + + /* + * Only can continue if the fields are correctly validated + * */ + if(valid){ + + /* + * Question if continue or not + * */ + final QuestionDialog questionDialog = new QuestionDialog(getActivity()); + questionDialog.setText(getActivity().getString(R.string.question_continue)); + questionDialog.setOnNegative(new NegativeResponse() { + @Override + public void onNegative(@NotNull DialogMaterial dialogMaterial) { + } + }); + questionDialog.setOnPositive(new PositiveResponse() { + @Override + public void onPositive() { + savePassword(); + } + }); + questionDialog.show(); + } + } + @OnTextChanged(value = R.id.etNewPin, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterNewPinChanged(Editable editable) { @@ -108,21 +158,34 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener } if (pinSecurityValidator.isValid()){ - CharSequence text = "Your password has been sucessfully changed!"; - int duration = Toast.LENGTH_SHORT; + //savePassword(); - Toast toast = Toast.makeText(getContext(), text, duration); - toast.show(); + //Now is valid + valid = true; - savePassword(etNewPin.getText().toString()); + /* + * Enable ok button to continue + * */ + btnOK.setEnabled(true); - - clearFields(); } } }); } + private void savePassword(){ + CharSequence text = "Your password has been sucessfully changed!"; + int duration = Toast.LENGTH_SHORT; + + Toast toast = Toast.makeText(getContext(), text, duration); + toast.show(); + + savePassword(etNewPin.getText().toString()); + + + clearFields(); + } + public void savePassword(String password) { String passwordEncripted = PasswordManager.encriptPassword(password); CrystalSecurityMonitor.getInstance(null).setPasswordSecurity(passwordEncripted); @@ -131,6 +194,15 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener @Override public void onValidationFailed(final ValidationField field) { + + //Still false + valid = false; + + /* + * Disable til it passes validations + * */ + btnOK.setEnabled(false); + this.getActivity().runOnUiThread(new Runnable() { @Override diff --git a/app/src/main/res/layout/fragment_pin_security.xml b/app/src/main/res/layout/fragment_pin_security.xml index b6582c6..6b288aa 100644 --- a/app/src/main/res/layout/fragment_pin_security.xml +++ b/app/src/main/res/layout/fragment_pin_security.xml @@ -36,4 +36,15 @@ android:textColor="@color/red" android:layout_below="@+id/etConfirmPin" /> +