mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-20 13: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 btnPos = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||||
Button btnNeutral = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
|
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) -> {
|
checkBoxEncrypt.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
warningText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
warningText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
||||||
passwordInfoText.setVisibility(isChecked && isBackupPasswordSet ? View.VISIBLE : View.GONE);
|
passwordInfoText.setVisibility(isChecked && isBackupPasswordSet ? View.VISIBLE : View.GONE);
|
||||||
checkBoxAccept.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
checkBoxAccept.setVisibility(isChecked ? View.GONE : View.VISIBLE);
|
||||||
checkBoxAccept.setChecked(false);
|
checkBoxAccept.setChecked(false);
|
||||||
btnPos.setEnabled(isChecked);
|
|
||||||
btnNeutral.setEnabled(isChecked);
|
stateValidator.enableIfValid();
|
||||||
});
|
});
|
||||||
|
|
||||||
checkBoxAccept.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
checkBoxAccept.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
btnPos.setEnabled(isChecked);
|
stateValidator.enableIfValid();
|
||||||
btnNeutral.setEnabled(isChecked);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
checkBoxExportAllGroups.setOnCheckedChangeListener((button, isChecked) -> {
|
checkBoxExportAllGroups.setOnCheckedChangeListener((button, isChecked) -> {
|
||||||
int visibility = isChecked ? View.GONE : View.VISIBLE;
|
int visibility = isChecked ? View.GONE : View.VISIBLE;
|
||||||
groupsSelectionLayout.setVisibility(visibility);
|
groupsSelectionLayout.setVisibility(visibility);
|
||||||
|
|
||||||
|
stateValidator.enableIfValid();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
groupsSelection.setOnDismissListener(stateValidator::enableIfValid);
|
||||||
|
|
||||||
btnPos.setOnClickListener(v -> {
|
btnPos.setOnClickListener(v -> {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
|
|
||||||
|
@ -257,7 +277,6 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
||||||
if (!checkBoxExportAllGroups.isChecked()) {
|
if (!checkBoxExportAllGroups.isChecked()) {
|
||||||
_exportFilter = getVaultEntryFilter(groupsSelection);
|
_exportFilter = getVaultEntryFilter(groupsSelection);
|
||||||
if (_exportFilter == null) {
|
if (_exportFilter == null) {
|
||||||
Toast.makeText(requireContext(), R.string.export_no_groups_selected, Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,4 +540,8 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
||||||
private interface StartExportCallback {
|
private interface StartExportCallback {
|
||||||
void exportVault(FinishExportCallback exportCb);
|
void exportVault(FinishExportCallback exportCb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private interface DialogStateValidator {
|
||||||
|
void enableIfValid();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue