diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt
index 9f78a797a..92e7a99c7 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt
@@ -37,20 +37,24 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val callbac
setCanceledOnTouchOutside(true)
show()
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
- val fileName = view.file_name.value
+ val filename = view.file_name.value
val extension = view.file_extension.value
- if (fileName.isEmpty() || extension.isEmpty()) {
+ if (filename.isEmpty()) {
context.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
- if (!fileName.isAValidFilename()) {
- context.toast(R.string.invalid_name)
+ if (extension.isEmpty()) {
+ context.toast(R.string.extension_cannot_be_empty)
return@setOnClickListener
}
- val newFile = File(file.parent, "$fileName.$extension")
+ val newFile = File(file.parent, "$filename.$extension")
+ if (!newFile.name.isAValidFilename()) {
+ context.toast(R.string.invalid_name)
+ return@setOnClickListener
+ }
if (context.needsStupidWritePermissions(file.absolutePath)) {
if (activity.isShowingPermDialog(file))
diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt
index 1cfc52470..ea85e4760 100644
--- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt
+++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt
@@ -17,8 +17,18 @@ class SaveAsDialog(val activity: Activity, val path: String, val callback: (save
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null)
view.apply {
file_path.text = activity.humanizePath(realPath)
- file_name.setText(path.getFilenameFromPath())
+ val fullName = path.getFilenameFromPath()
+ val dotAt = fullName.lastIndexOf(".")
+ var name = fullName
+
+ if (dotAt > 0) {
+ name = fullName.substring(0, dotAt)
+ val extension = fullName.substring(dotAt + 1)
+ view.file_extension.setText(extension)
+ }
+
+ file_name.setText(name)
file_path.setOnClickListener {
FilePickerDialog(activity, realPath, false, false, listener = object : FilePickerDialog.OnFilePickerListener {
override fun onSuccess(pickedPath: String) {
@@ -43,19 +53,25 @@ class SaveAsDialog(val activity: Activity, val path: String, val callback: (save
show()
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
val filename = view.file_name.value
+ val extension = view.file_extension.value
if (filename.isEmpty()) {
context.toast(R.string.filename_cannot_be_empty)
return@setOnClickListener
}
- if (!filename.isAValidFilename()) {
+ if (extension.isEmpty()) {
+ context.toast(R.string.extension_cannot_be_empty)
+ return@setOnClickListener
+ }
+
+ val newFile = File(realPath, "$filename.$extension")
+ if (!newFile.name.isAValidFilename()) {
context.toast(R.string.filename_invalid_characters)
return@setOnClickListener
}
- val newPath = File(realPath, filename).absolutePath
- callback.invoke(newPath)
+ callback.invoke(newFile.absolutePath)
dismiss()
})
}
diff --git a/app/src/main/res/layout/dialog_save_as.xml b/app/src/main/res/layout/dialog_save_as.xml
index f94203323..d3777bc2b 100644
--- a/app/src/main/res/layout/dialog_save_as.xml
+++ b/app/src/main/res/layout/dialog_save_as.xml
@@ -30,4 +30,17 @@
android:layout_marginBottom="@dimen/activity_margin"
android:singleLine="true"/>
+
+
+
+
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index f2154b366..9603538f5 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -81,6 +81,7 @@
Dateiname darf nicht leer sein
Filename contains invalid characters
Dateiendung
+ Extension cannot be empty
Sortieren nach
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 21d859f9f..902df993c 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -81,6 +81,7 @@
El nombre de archivo no puede estar vacío
Filename contains invalid characters
Extensión
+ Extension cannot be empty
Ordenar por
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index e7bb7661d..731a6aa11 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -81,6 +81,7 @@
Il nome del file non deve essere vuoto
Il nome contiene caratteri non validi
Estensione
+ Extension cannot be empty
Ordina per
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 5726bd372..7aa0308b6 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -81,6 +81,7 @@
ファイル名は空にできません
ファイル名に無効な文字が含まれています
拡張
+ Extension cannot be empty
並び替え
diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml
index 14f5cb9c1..f6d56f4f8 100644
--- a/app/src/main/res/values-pt-rPT/strings.xml
+++ b/app/src/main/res/values-pt-rPT/strings.xml
@@ -81,6 +81,7 @@
O nome do ficheiro não pode estar vazio
O nome do ficheiro contém caracteres inválidos
Extensão
+ Extension cannot be empty
Ordenar por
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 318ce824f..63a47dfa9 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -82,6 +82,7 @@
Имя файла не может быть пустым
Имя файла содержит недопустимые символы
Расширение
+ Extension cannot be empty
Сортировать по
diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml
index 1bb236c43..f463aa355 100644
--- a/app/src/main/res/values-sv/strings.xml
+++ b/app/src/main/res/values-sv/strings.xml
@@ -81,6 +81,7 @@
Du måste ange ett filnamn
Filename contains invalid characters
Filändelse
+ Extension cannot be empty
Sort by
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 138bdd6b3..d23948606 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -82,6 +82,7 @@
文件名不能为空
文件名包含非法字符
扩展名
+ Extension cannot be empty
排序方式
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8e022c503..f55d2e886 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -81,6 +81,7 @@
Filename cannot be empty
Filename contains invalid characters
Extension
+ Extension cannot be empty
Sort by