fix crash when trying to create folder with empty name

This commit is contained in:
Skalii 2021-02-19 16:36:01 +02:00
parent 7373a2c8c2
commit f12cbd0aea

View file

@ -90,20 +90,23 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
private void updateFileNameFromEditText(String name) {
rightButtonEnabled = false;
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(name).find()) {
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
} else if (Algorithms.isEmpty(name.trim())) {
if (Algorithms.isBlank(name)) {
nameTextBox.setError(getString(R.string.empty_filename));
} else {
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), name);
if (destFolder.exists()) {
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(name).find()) {
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
} else {
nameTextBox.setError(null);
folderName = name;
rightButtonEnabled = true;
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), name);
if (destFolder.exists()) {
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
} else {
nameTextBox.setError(null);
nameTextBox.setErrorEnabled(false);
rightButtonEnabled = true;
}
}
}
folderName = name;
updateBottomButtons();
}
@ -117,11 +120,15 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
protected void onRightBottomButtonClick() {
AndroidUtils.hideSoftKeyboard(requireActivity(), editText);
Fragment fragment = getTargetFragment();
if (fragment instanceof OnTrackFolderAddListener) {
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
listener.onTrackFolderAdd(folderName);
if (!Algorithms.isBlank(folderName)) {
if (fragment instanceof OnTrackFolderAddListener) {
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
listener.onTrackFolderAdd(folderName);
}
dismiss();
} else {
updateFileNameFromEditText(folderName);
}
dismiss();
}
@Override