Protected content: improved repeated password check

pull/209/head
M66B 2 years ago
parent d89b3edc73
commit 69d5c619a3

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -39,6 +38,7 @@ import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.AlignmentSpan;
import android.text.style.BackgroundColorSpan;
import android.text.style.BulletSpan;
@ -593,7 +593,7 @@ public class StyleHelper {
}
});
Dialog dialog = new AlertDialog.Builder(context)
AlertDialog dialog = new AlertDialog.Builder(context)
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
@ -601,13 +601,6 @@ public class StyleHelper {
String password1 = etPassword1.getEditText().getText().toString();
String password2 = etPassword2.getEditText().getText().toString();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean debug = prefs.getBoolean("debug", false);
if (TextUtils.isEmpty(password1) && !(debug || BuildConfig.DEBUG))
ToastEx.makeText(context, R.string.title_setup_password_missing, Toast.LENGTH_LONG).show();
else {
if (password1.equals(password2)) {
int start = etBody.getSelectionStart();
int end = etBody.getSelectionEnd();
boolean selection = (start >= 0 && start < end);
@ -705,9 +698,6 @@ public class StyleHelper {
}
}.execute(context, owner, args, "protect");
}
} else
ToastEx.makeText(context, R.string.title_setup_password_different, Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton(android.R.string.cancel, null)
@ -717,6 +707,34 @@ public class StyleHelper {
// WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
dialog.show();
Button btnOk = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
TextWatcher w = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing
}
@Override
public void afterTextChanged(Editable s) {
String p1 = etPassword1.getEditText().getText().toString();
String p2 = etPassword2.getEditText().getText().toString();
btnOk.setEnabled(!TextUtils.isEmpty(p1) && p1.equals(p2));
etPassword2.setHint(!TextUtils.isEmpty(p2) && !p2.equals(p1)
? R.string.title_setup_password_different
: R.string.title_setup_password_repeat);
}
};
etPassword1.getEditText().addTextChangedListener(w);
etPassword2.getEditText().addTextChangedListener(w);
w.afterTextChanged(null);
return true;
}

Loading…
Cancel
Save