mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Disallow empty strings to pass through text input dialogs
This also fixes a crash for certain importers than could occur if the user entered an empty password.
This commit is contained in:
parent
ee15a61403
commit
ee6a020f4d
1 changed files with 30 additions and 28 deletions
|
@ -7,7 +7,6 @@ import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -18,7 +17,6 @@ import android.view.WindowManager;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.NumberPicker;
|
import android.widget.NumberPicker;
|
||||||
|
@ -34,6 +32,7 @@ import com.beemdevelopment.aegis.Preferences;
|
||||||
import com.beemdevelopment.aegis.R;
|
import com.beemdevelopment.aegis.R;
|
||||||
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
import com.beemdevelopment.aegis.helpers.EditTextHelper;
|
||||||
import com.beemdevelopment.aegis.helpers.PasswordStrengthHelper;
|
import com.beemdevelopment.aegis.helpers.PasswordStrengthHelper;
|
||||||
|
import com.beemdevelopment.aegis.helpers.SimpleTextWatcher;
|
||||||
import com.beemdevelopment.aegis.importers.DatabaseImporter;
|
import com.beemdevelopment.aegis.importers.DatabaseImporter;
|
||||||
import com.beemdevelopment.aegis.ui.tasks.KeyDerivationTask;
|
import com.beemdevelopment.aegis.ui.tasks.KeyDerivationTask;
|
||||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||||
|
@ -126,7 +125,7 @@ public class Dialogs {
|
||||||
TextInputLayout textPasswordWrapper = view.findViewById(R.id.text_password_wrapper);
|
TextInputLayout textPasswordWrapper = view.findViewById(R.id.text_password_wrapper);
|
||||||
CheckBox switchToggleVisibility = view.findViewById(R.id.check_toggle_visibility);
|
CheckBox switchToggleVisibility = view.findViewById(R.id.check_toggle_visibility);
|
||||||
|
|
||||||
switchToggleVisibility.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener) (buttonView, isChecked) -> {
|
switchToggleVisibility.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
textPassword.setTransformationMethod(null);
|
textPassword.setTransformationMethod(null);
|
||||||
textPasswordConfirm.setTransformationMethod(null);
|
textPasswordConfirm.setTransformationMethod(null);
|
||||||
|
@ -177,28 +176,17 @@ public class Dialogs {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
TextWatcher watcher = new TextWatcher() {
|
TextWatcher watcher = new SimpleTextWatcher(text -> {
|
||||||
@Override
|
boolean equal = EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm);
|
||||||
public void onTextChanged(CharSequence c, int start, int before, int count) {
|
buttonOK.get().setEnabled(equal);
|
||||||
boolean equal = EditTextHelper.areEditTextsEqual(textPassword, textPasswordConfirm);
|
|
||||||
buttonOK.get().setEnabled(equal);
|
|
||||||
|
|
||||||
Strength strength = zxcvbn.measure(textPassword.getText());
|
Strength strength = zxcvbn.measure(textPassword.getText());
|
||||||
barPasswordStrength.setProgress(strength.getScore());
|
barPasswordStrength.setProgress(strength.getScore());
|
||||||
barPasswordStrength.setProgressTintList(ColorStateList.valueOf(Color.parseColor(PasswordStrengthHelper.getColor(strength.getScore()))));
|
barPasswordStrength.setProgressTintList(ColorStateList.valueOf(Color.parseColor(PasswordStrengthHelper.getColor(strength.getScore()))));
|
||||||
textPasswordStrength.setText((textPassword.getText().length() != 0) ? PasswordStrengthHelper.getString(strength.getScore(), activity) : "");
|
textPasswordStrength.setText((textPassword.getText().length() != 0) ? PasswordStrengthHelper.getString(strength.getScore(), activity) : "");
|
||||||
textPasswordWrapper.setError(strength.getFeedback().getWarning());
|
textPasswordWrapper.setError(strength.getFeedback().getWarning());
|
||||||
strength.wipe();
|
strength.wipe();
|
||||||
}
|
});
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence c, int start, int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable c) {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
textPassword.addTextChangedListener(watcher);
|
textPassword.addTextChangedListener(watcher);
|
||||||
textPasswordConfirm.addTextChangedListener(watcher);
|
textPasswordConfirm.addTextChangedListener(watcher);
|
||||||
|
|
||||||
|
@ -206,8 +194,14 @@ public class Dialogs {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showTextInputDialog(Context context, @StringRes int titleId, @StringRes int messageId, @StringRes int hintId, TextInputListener listener, DialogInterface.OnCancelListener cancelListener, boolean isSecret) {
|
private static void showTextInputDialog(Context context, @StringRes int titleId, @StringRes int messageId, @StringRes int hintId, TextInputListener listener, DialogInterface.OnCancelListener cancelListener, boolean isSecret) {
|
||||||
|
final AtomicReference<Button> buttonOK = new AtomicReference<>();
|
||||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_text_input, null);
|
View view = LayoutInflater.from(context).inflate(R.layout.dialog_text_input, null);
|
||||||
TextInputEditText input = view.findViewById(R.id.text_input);
|
TextInputEditText input = view.findViewById(R.id.text_input);
|
||||||
|
input.addTextChangedListener(new SimpleTextWatcher(text -> {
|
||||||
|
if (buttonOK.get() != null) {
|
||||||
|
buttonOK.get().setEnabled(!text.toString().isEmpty());
|
||||||
|
}
|
||||||
|
}));
|
||||||
TextInputLayout inputLayout = view.findViewById(R.id.text_input_layout);
|
TextInputLayout inputLayout = view.findViewById(R.id.text_input_layout);
|
||||||
if (isSecret) {
|
if (isSecret) {
|
||||||
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||||
|
@ -217,10 +211,7 @@ public class Dialogs {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
||||||
.setTitle(titleId)
|
.setTitle(titleId)
|
||||||
.setView(view)
|
.setView(view)
|
||||||
.setPositiveButton(android.R.string.ok, (dialog1, which) -> {
|
.setPositiveButton(android.R.string.ok, null);
|
||||||
char[] text = EditTextHelper.getEditTextChars(input);
|
|
||||||
listener.onTextInputResult(text);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (cancelListener != null) {
|
if (cancelListener != null) {
|
||||||
builder.setOnCancelListener(cancelListener);
|
builder.setOnCancelListener(cancelListener);
|
||||||
|
@ -231,6 +222,17 @@ public class Dialogs {
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog dialog = builder.create();
|
AlertDialog dialog = builder.create();
|
||||||
|
dialog.setOnShowListener(d -> {
|
||||||
|
Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
|
button.setEnabled(false);
|
||||||
|
buttonOK.set(button);
|
||||||
|
|
||||||
|
button.setOnClickListener(v -> {
|
||||||
|
char[] text = EditTextHelper.getEditTextChars(input);
|
||||||
|
listener.onTextInputResult(text);
|
||||||
|
dialog.dismiss();
|
||||||
|
});
|
||||||
|
});
|
||||||
dialog.setCanceledOnTouchOutside(true);
|
dialog.setCanceledOnTouchOutside(true);
|
||||||
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
||||||
showSecureDialog(dialog);
|
showSecureDialog(dialog);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue