diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java index 5546f7a8c..cf8af8b7f 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/MainActivity.java @@ -242,18 +242,19 @@ public class MainActivity extends AppCompatActivity public void onClick(View v) { final String newDirName = dirNameET.getText().toString().trim(); - if (!newDirName.isEmpty()) { - final File newDir = new File(dir.getParent(), newDirName); + if (newDirName.isEmpty()) { + Utils.showToast(getApplicationContext(), R.string.rename_folder_empty); + return; + } - if (dir.renameTo(newDir)) { - Utils.showToast(getApplicationContext(), R.string.rename_folder_ok); - alertDialog.dismiss(); - actionMode.finish(); - final String[] newDirPath = new String[]{newDir.getAbsolutePath()}; - MediaScannerConnection.scanFile(getApplicationContext(), newDirPath, null, MainActivity.this); - } else { - Utils.showToast(getApplicationContext(), R.string.rename_folder_error); - } + final File newDir = new File(dir.getParent(), newDirName); + + if (dir.renameTo(newDir)) { + Utils.showToast(getApplicationContext(), R.string.rename_folder_ok); + alertDialog.dismiss(); + actionMode.finish(); + final String[] newDirPath = new String[]{newDir.getAbsolutePath()}; + MediaScannerConnection.scanFile(getApplicationContext(), newDirPath, null, MainActivity.this); } else { Utils.showToast(getApplicationContext(), R.string.rename_folder_error); } diff --git a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java index c54bb5eb8..4af2a2a44 100644 --- a/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java +++ b/app/src/main/java/com/simplemobiletools/gallery/activities/ViewPagerActivity.java @@ -195,19 +195,20 @@ public class ViewPagerActivity extends AppCompatActivity final String fileName = fileNameET.getText().toString().trim(); final String extension = extensionET.getText().toString().trim(); - if (!fileName.isEmpty() && !extension.isEmpty()) { - final File newFile = new File(file.getParent(), fileName + "." + extension); + if (fileName.isEmpty() || extension.isEmpty()) { + Utils.showToast(getApplicationContext(), R.string.rename_file_empty); + return; + } - if (file.renameTo(newFile)) { - photos.set(pager.getCurrentItem(), newFile.getAbsolutePath()); + final File newFile = new File(file.getParent(), fileName + "." + extension); - final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()}; - MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); - updateActionbarTitle(); - alertDialog.dismiss(); - } else { - Utils.showToast(getApplicationContext(), R.string.rename_file_error); - } + if (file.renameTo(newFile)) { + photos.set(pager.getCurrentItem(), newFile.getAbsolutePath()); + + final String[] changedFiles = {file.getAbsolutePath(), newFile.getAbsolutePath()}; + MediaScannerConnection.scanFile(getApplicationContext(), changedFiles, null, null); + updateActionbarTitle(); + alertDialog.dismiss(); } else { Utils.showToast(getApplicationContext(), R.string.rename_file_error); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e68e12c65..457e3ea57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,7 +9,9 @@ Rename file Rename folder Could not rename the file + File name must not be empty Could not rename the folder + Folder name must not be empty Folder renamed successfully File name Folder name