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,18 +242,19 @@ 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()) {
final File newDir = new File(dir.getParent(), newDirName); Utils.showToast(getApplicationContext(), R.string.rename_folder_empty);
return;
}
if (dir.renameTo(newDir)) { final File newDir = new File(dir.getParent(), newDirName);
Utils.showToast(getApplicationContext(), R.string.rename_folder_ok);
alertDialog.dismiss(); if (dir.renameTo(newDir)) {
actionMode.finish(); Utils.showToast(getApplicationContext(), R.string.rename_folder_ok);
final String[] newDirPath = new String[]{newDir.getAbsolutePath()}; alertDialog.dismiss();
MediaScannerConnection.scanFile(getApplicationContext(), newDirPath, null, MainActivity.this); actionMode.finish();
} else { final String[] newDirPath = new String[]{newDir.getAbsolutePath()};
Utils.showToast(getApplicationContext(), R.string.rename_folder_error); MediaScannerConnection.scanFile(getApplicationContext(), newDirPath, null, MainActivity.this);
}
} else { } else {
Utils.showToast(getApplicationContext(), R.string.rename_folder_error); Utils.showToast(getApplicationContext(), R.string.rename_folder_error);
} }

View file

@ -195,19 +195,20 @@ 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()) {
final File newFile = new File(file.getParent(), fileName + "." + extension); Utils.showToast(getApplicationContext(), R.string.rename_file_empty);
return;
}
if (file.renameTo(newFile)) { final File newFile = new File(file.getParent(), fileName + "." + extension);
photos.set(pager.getCurrentItem(), newFile.getAbsolutePath());
final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()}; if (file.renameTo(newFile)) {
MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); photos.set(pager.getCurrentItem(), newFile.getAbsolutePath());
updateActionbarTitle();
alertDialog.dismiss(); final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()};
} else { MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null);
Utils.showToast(getApplicationContext(), R.string.rename_file_error); updateActionbarTitle();
} alertDialog.dismiss();
} else { } else {
Utils.showToast(getApplicationContext(), R.string.rename_file_error); 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>