Fixed bug where OK was still enabled when the passwords don't match. Renamed toShortWarning to tooShortWarning

This commit is contained in:
Ullas-Aithal 2021-03-04 11:54:16 +05:30
parent 1963cfbda5
commit 914c4c4aa5
4 changed files with 13 additions and 14 deletions

View file

@ -37,7 +37,7 @@ public class PasswordEntryDialog extends AppCompatDialog
private final TextInputEditText passwordInput;
private final EditText passwordConfirm;
private final Button okButton;
private final TextView toShortWarning;
private final TextView tooShortWarning;
public PasswordEntryDialog(Context context, Mode newMode, boolean blockAccessibility, boolean blockAutofill, PasswordEnteredCallback newCallback) {
super(context, Tools.getThemeResource(context, R.attr.dialogTheme));
@ -48,8 +48,8 @@ public class PasswordEntryDialog extends AppCompatDialog
TextInputLayout passwordLayout = findViewById(R.id.passwordInputLayout);
passwordInput = findViewById(R.id.passwordInput);
passwordConfirm = findViewById(R.id.passwordConfirm);
toShortWarning = findViewById(R.id.toShortWarning);
toShortWarning.setText(getContext().getString(R.string.settings_label_short_password, Constants.AUTH_MIN_PASSWORD_LENGTH));
tooShortWarning = findViewById(R.id.tooShortWarning);
tooShortWarning.setText(getContext().getString(R.string.settings_label_short_password, Constants.AUTH_MIN_PASSWORD_LENGTH));
ConfirmedPasswordTransformationHelper.setup(passwordLayout, passwordInput, passwordConfirm);
if (blockAccessibility) {
@ -87,12 +87,11 @@ public class PasswordEntryDialog extends AppCompatDialog
// TextWatcher
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (passwordInput.getEditableText().length() >= Constants.AUTH_MIN_PASSWORD_LENGTH) {
toShortWarning.setVisibility(View.GONE);
if (TextUtils.equals(passwordInput.getEditableText(), passwordConfirm.getEditableText()))
okButton.setEnabled(true);
tooShortWarning.setVisibility(View.GONE);
okButton.setEnabled(TextUtils.equals(passwordInput.getEditableText(), passwordConfirm.getEditableText()));
}
else {
toShortWarning.setVisibility(View.VISIBLE);
tooShortWarning.setVisibility(View.VISIBLE);
okButton.setEnabled(false);
}
}

View file

@ -86,7 +86,7 @@ public class CredentialsPreference extends DialogPreference
private TextInputLayout passwordLayout;
private TextInputEditText passwordInput;
private EditText passwordConfirm;
private TextView toShortWarning;
private TextView tooShortWarning;
private Button btnSave;
@ -141,7 +141,7 @@ public class CredentialsPreference extends DialogPreference
passwordConfirm.setImportantForAutofill(View.IMPORTANT_FOR_AUTOFILL_NO);
}
toShortWarning = view.findViewById(R.id.toShortWarning);
tooShortWarning = view.findViewById(R.id.tooShortWarning);
passwordInput.addTextChangedListener(this);
passwordConfirm.addTextChangedListener(this);
@ -231,13 +231,13 @@ public class CredentialsPreference extends DialogPreference
String password = passwordInput.getEditableText().toString();
if (password.length() >= minLength) {
toShortWarning.setVisibility(View.GONE);
tooShortWarning.setVisibility(View.GONE);
String confirm = passwordConfirm.getEditableText().toString();
boolean canSave = !password.isEmpty() && !confirm.isEmpty() && password.equals(confirm);
btnSave.setEnabled(canSave);
} else {
toShortWarning.setVisibility(View.VISIBLE);
tooShortWarning.setVisibility(View.VISIBLE);
}
}
@ -274,7 +274,7 @@ public class CredentialsPreference extends DialogPreference
minLength = isPassword ? Constants.AUTH_MIN_PASSWORD_LENGTH : Constants.AUTH_MIN_PIN_LENGTH;
int shortWarningRes = isPassword ? R.string.settings_label_short_password : R.string.settings_label_short_pin;
toShortWarning.setText(getContext().getString(shortWarningRes, minLength));
tooShortWarning.setText(getContext().getString(shortWarningRes, minLength));
passwordInput.requestFocus();
UIHelper.showKeyboard(getContext(), passwordInput);

View file

@ -49,7 +49,7 @@
android:autofillHints="password" />
<TextView
android:id="@+id/toShortWarning"
android:id="@+id/tooShortWarning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin"

View file

@ -34,7 +34,7 @@
android:inputType="textPassword" />
<TextView
android:id="@+id/toShortWarning"
android:id="@+id/tooShortWarning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_margin"