mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-22 14:59:14 +00:00
Merge pull request #1067 from orange-elephant/export-dialog-ux
Only enable export buttons if options are in a valid state
This commit is contained in:
commit
0eccc875b0
1 changed files with 28 additions and 5 deletions
|
@ -201,25 +201,45 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
Button btnPos = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
Button btnNeutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
|
||||
|
||||
DialogStateValidator stateValidator = () -> {
|
||||
boolean noGroupsSelected = groupsSelection.getCheckedItems().isEmpty();
|
||||
boolean validState = (checkBoxEncrypt.isChecked() || checkBoxAccept.isChecked()) &&
|
||||
(checkBoxExportAllGroups.isChecked() || !noGroupsSelected);
|
||||
|
||||
if (noGroupsSelected && groupsSelectionLayout.getError() == null) {
|
||||
CharSequence errorMsg = getString(R.string.export_no_groups_selected);
|
||||
groupsSelectionLayout.setError(errorMsg);
|
||||
} else if (!noGroupsSelected && groupsSelectionLayout.getError() != null) {
|
||||
groupsSelectionLayout.setError(null);
|
||||
groupsSelectionLayout.setErrorEnabled(false);
|
||||
}
|
||||
|
||||
btnPos.setEnabled(validState);
|
||||
btnNeutral.setEnabled(validState);
|
||||
};
|
||||
|
||||
checkBoxEncrypt.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
warningText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
||||
passwordInfoText.setVisibility(isChecked && isBackupPasswordSet ? View.VISIBLE : View.GONE);
|
||||
checkBoxAccept.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
||||
checkBoxAccept.setChecked(false);
|
||||
btnPos.setEnabled(isChecked);
|
||||
btnNeutral.setEnabled(isChecked);
|
||||
|
||||
stateValidator.enableIfValid();
|
||||
});
|
||||
|
||||
checkBoxAccept.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
btnPos.setEnabled(isChecked);
|
||||
btnNeutral.setEnabled(isChecked);
|
||||
stateValidator.enableIfValid();
|
||||
});
|
||||
|
||||
checkBoxExportAllGroups.setOnCheckedChangeListener((button, isChecked) -> {
|
||||
int visibility = isChecked ? View.GONE : View.VISIBLE;
|
||||
groupsSelectionLayout.setVisibility(visibility);
|
||||
|
||||
stateValidator.enableIfValid();
|
||||
});
|
||||
|
||||
groupsSelection.setOnDismissListener(stateValidator::enableIfValid);
|
||||
|
||||
btnPos.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
|
||||
|
@ -257,7 +277,6 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
if (!checkBoxExportAllGroups.isChecked()) {
|
||||
_exportFilter = getVaultEntryFilter(groupsSelection);
|
||||
if (_exportFilter == null) {
|
||||
Toast.makeText(requireContext(), R.string.export_no_groups_selected, Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -521,4 +540,8 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
private interface StartExportCallback {
|
||||
void exportVault(FinishExportCallback exportCb);
|
||||
}
|
||||
|
||||
private interface DialogStateValidator {
|
||||
void enableIfValid();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue