reformat the rename conditions a bit

This commit is contained in:
tibbi 2016-03-26 15:37:12 +01:00
parent 5c144a607b
commit 1da4050d4a
3 changed files with 26 additions and 22 deletions

View file

@ -242,7 +242,11 @@ public class MainActivity extends AppCompatActivity
public void onClick(View v) { public void onClick(View v) {
final String newDirName = dirNameET.getText().toString().trim(); final String newDirName = dirNameET.getText().toString().trim();
if (!newDirName.isEmpty()) { if (newDirName.isEmpty()) {
Utils.showToast(getApplicationContext(), R.string.rename_folder_empty);
return;
}
final File newDir = new File(dir.getParent(), newDirName); final File newDir = new File(dir.getParent(), newDirName);
if (dir.renameTo(newDir)) { if (dir.renameTo(newDir)) {
@ -254,9 +258,6 @@ public class MainActivity extends AppCompatActivity
} else { } else {
Utils.showToast(getApplicationContext(), R.string.rename_folder_error); Utils.showToast(getApplicationContext(), R.string.rename_folder_error);
} }
} else {
Utils.showToast(getApplicationContext(), R.string.rename_folder_error);
}
} }
}); });
} }

View file

@ -195,7 +195,11 @@ public class ViewPagerActivity extends AppCompatActivity
final String fileName = fileNameET.getText().toString().trim(); final String fileName = fileNameET.getText().toString().trim();
final String extension = extensionET.getText().toString().trim(); final String extension = extensionET.getText().toString().trim();
if (!fileName.isEmpty() && !extension.isEmpty()) { if (fileName.isEmpty() || extension.isEmpty()) {
Utils.showToast(getApplicationContext(), R.string.rename_file_empty);
return;
}
final File newFile = new File(file.getParent(), fileName + "." + extension); final File newFile = new File(file.getParent(), fileName + "." + extension);
if (file.renameTo(newFile)) { if (file.renameTo(newFile)) {
@ -208,9 +212,6 @@ public class ViewPagerActivity extends AppCompatActivity
} else { } else {
Utils.showToast(getApplicationContext(), R.string.rename_file_error); Utils.showToast(getApplicationContext(), R.string.rename_file_error);
} }
} else {
Utils.showToast(getApplicationContext(), R.string.rename_file_error);
}
} }
}); });
} }

View file

@ -9,7 +9,9 @@
<string name="rename_file">Rename file</string> <string name="rename_file">Rename file</string>
<string name="rename_folder">Rename folder</string> <string name="rename_folder">Rename folder</string>
<string name="rename_file_error">Could not rename the file</string> <string name="rename_file_error">Could not rename the file</string>
<string name="rename_file_empty">File name must not be empty</string>
<string name="rename_folder_error">Could not rename the folder</string> <string name="rename_folder_error">Could not rename the folder</string>
<string name="rename_folder_empty">Folder name must not be empty</string>
<string name="rename_folder_ok">Folder renamed successfully</string> <string name="rename_folder_ok">Folder renamed successfully</string>
<string name="file_name">File name</string> <string name="file_name">File name</string>
<string name="folder_name">Folder name</string> <string name="folder_name">Folder name</string>