Merge pull request #325 from michaelschattgen/fix-confirm-password

Improve confirm password functionality
This commit is contained in:
Alexander Bakker 2020-03-04 10:25:29 +01:00 committed by GitHub
commit 3d51b84188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -93,11 +93,12 @@ public class Dialogs {
switchToggleVisibility.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) (buttonView, isChecked) -> { switchToggleVisibility.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) (buttonView, isChecked) -> {
if (isChecked) { if (isChecked) {
textPassword.setTransformationMethod(null); textPassword.setTransformationMethod(null);
textPasswordConfirm.setTransformationMethod(null);
textPassword.clearFocus(); textPassword.clearFocus();
textPasswordConfirm.setEnabled(false); textPasswordConfirm.clearFocus();
} else { } else {
textPassword.setTransformationMethod(new PasswordTransformationMethod()); textPassword.setTransformationMethod(new PasswordTransformationMethod());
textPasswordConfirm.setEnabled(true); textPasswordConfirm.setTransformationMethod(new PasswordTransformationMethod());
} }
}); });
@ -116,7 +117,7 @@ public class Dialogs {
// replace the default listener // replace the default listener
button.setOnClickListener(v -> { button.setOnClickListener(v -> {
if (!EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm) && !switchToggleVisibility.isChecked()) { if (!EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm)) {
return; return;
} }
@ -141,7 +142,7 @@ public class Dialogs {
TextWatcher watcher = new TextWatcher() { TextWatcher watcher = new TextWatcher() {
public void onTextChanged(CharSequence c, int start, int before, int count) { public void onTextChanged(CharSequence c, int start, int before, int count) {
boolean equal = EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm); boolean equal = EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm);
buttonOK.get().setEnabled(equal || switchToggleVisibility.isChecked()); buttonOK.get().setEnabled(equal);
} }
public void beforeTextChanged(CharSequence c, int start, int count, int after) { public void beforeTextChanged(CharSequence c, int start, int count, int after) {

View file

@ -45,11 +45,12 @@ public class CustomAuthenticatedSlide extends Fragment implements ISlidePolicy,
_checkPasswordVisibility.setOnCheckedChangeListener((buttonView, isChecked) -> { _checkPasswordVisibility.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) { if (isChecked) {
_textPassword.setTransformationMethod(null); _textPassword.setTransformationMethod(null);
_textPasswordConfirm.setTransformationMethod(null);
_textPassword.clearFocus(); _textPassword.clearFocus();
_textPasswordConfirm.setEnabled(false); _textPasswordConfirm.clearFocus();
} else { } else {
_textPassword.setTransformationMethod(new PasswordTransformationMethod()); _textPassword.setTransformationMethod(new PasswordTransformationMethod());
_textPasswordConfirm.setEnabled(true); _textPasswordConfirm.setTransformationMethod(new PasswordTransformationMethod());
} }
}); });
@ -113,7 +114,7 @@ public class CustomAuthenticatedSlide extends Fragment implements ISlidePolicy,
// intentional fallthrough // intentional fallthrough
case CustomAuthenticationSlide.CRYPT_TYPE_PASS: case CustomAuthenticationSlide.CRYPT_TYPE_PASS:
if (EditTextHelper.getEditTextChars(_textPassword).length > 0) { if (EditTextHelper.getEditTextChars(_textPassword).length > 0) {
return EditTextHelper.areEditTextsEqual(_textPassword, _textPasswordConfirm) || _checkPasswordVisibility.isChecked(); return EditTextHelper.areEditTextsEqual(_textPassword, _textPasswordConfirm);
} }
return false; return false;
@ -125,7 +126,7 @@ public class CustomAuthenticatedSlide extends Fragment implements ISlidePolicy,
@Override @Override
public void onUserIllegallyRequestedNextPage() { public void onUserIllegallyRequestedNextPage() {
String message; String message;
if (!EditTextHelper.areEditTextsEqual(_textPassword, _textPasswordConfirm) && !_checkPasswordVisibility.isChecked()) { if (!EditTextHelper.areEditTextsEqual(_textPassword, _textPasswordConfirm)) {
message = getString(R.string.password_equality_error); message = getString(R.string.password_equality_error);
View view = getView(); View view = getView();