check for already existing files or directories

This commit is contained in:
tibbi 2016-07-14 12:14:23 +02:00
parent 42529d81ab
commit 1d45e4e0cb
2 changed files with 6 additions and 1 deletions

View File

@ -163,7 +163,11 @@ public class ItemsFragment extends android.support.v4.app.Fragment
final EditText itemName = (EditText) newItemView.findViewById(R.id.item_name);
final String name = itemName.getText().toString().trim();
if (Utils.isNameValid(name)) {
File file = new File(mPath, name);
final File file = new File(mPath, name);
if (file.exists()) {
Utils.showToast(getContext(), R.string.name_taken);
return;
}
final RadioGroup radio = (RadioGroup) newItemView.findViewById(R.id.dialog_radio_group);
if (radio.getCheckedRadioButtonId() == R.id.dialog_radio_directory) {
if (!createDirectory(file, alertDialog)) {

View File

@ -5,6 +5,7 @@
<string name="create_new">Create new item</string>
<string name="directory">Directory</string>
<string name="file">File</string>
<string name="name_taken">Directory or file with that name already exists</string>
<string name="invalid_name">The name contains invalid characters</string>
<string name="error_occurred">An unknown error occurred</string>
<string name="delete">Delete</string>