-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
This commit is contained in:
parent
3d9d57d0fa
commit
013a3b841f
3 changed files with 92 additions and 7 deletions
|
@ -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<List<GeneralSetting>> 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,6 +158,22 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener
|
|||
}
|
||||
|
||||
if (pinSecurityValidator.isValid()){
|
||||
//savePassword();
|
||||
|
||||
//Now is valid
|
||||
valid = true;
|
||||
|
||||
/*
|
||||
* Enable ok button to continue
|
||||
* */
|
||||
btnOK.setEnabled(true);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void savePassword(){
|
||||
CharSequence text = "Your password has been sucessfully changed!";
|
||||
int duration = Toast.LENGTH_SHORT;
|
||||
|
||||
|
@ -119,9 +185,6 @@ public class PinSecurityFragment extends Fragment implements UIValidatorListener
|
|||
|
||||
clearFields();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void savePassword(String password) {
|
||||
String passwordEncripted = PasswordManager.encriptPassword(password);
|
||||
|
@ -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
|
||||
|
|
|
@ -36,4 +36,15 @@
|
|||
android:textColor="@color/red"
|
||||
android:layout_below="@+id/etConfirmPin" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnOK"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/WhiteButton"
|
||||
android:text="@string/ok"
|
||||
android:layout_below="@+id/etConfirmPin"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textColor="@color/black"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -369,6 +369,8 @@
|
|||
<string name="permission_denied_camera">Permission Denied. You cannot use the QR camera. Please allow this permission in App Settings.</string>
|
||||
<string name="permission_granted_camera">Great!! Now you can use the QR camera.</string>
|
||||
|
||||
<string name="question_continue">¿Are you sure to continue?</string>
|
||||
|
||||
<string name="select">"Select</string>
|
||||
<string name="are_you_sure">"Are you sure?</string>
|
||||
<string name="is_already_added">is already added</string>
|
||||
|
|
Loading…
Reference in a new issue