From fa4cadebb4e06d567b0ada382a8c610f2a264bfc Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 17 Nov 2016 16:23:49 +0100 Subject: [PATCH] check if new file/dir names are valid --- .../gallery/dialogs/CopyDialog.kt | 11 +++++------ .../gallery/dialogs/PickAlbumDialog.kt | 7 +++---- .../gallery/dialogs/RenameDirectoryDialog.kt | 18 ++++++++++-------- .../gallery/dialogs/RenameFileDialog.kt | 14 +++++++++----- .../gallery/dialogs/SaveAsDialog.kt | 7 +++---- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-pt-rPT/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 13 files changed, 38 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt index a3626a63d..3d605d97e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/CopyDialog.kt @@ -19,24 +19,23 @@ import java.util.* class CopyDialog(val activity: SimpleActivity, val files: ArrayList, val copyMoveListener: CopyMoveTask.CopyMoveListener) { init { - val context = activity - val view = LayoutInflater.from(context).inflate(R.layout.dialog_copy_move, null) + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_copy_move, null) val sourcePath = files[0].parent.trimEnd('/') var destinationPath = "" - view.source.text = context.humanizePath(sourcePath) + view.source.text = activity.humanizePath(sourcePath) view.destination.setOnClickListener { PickAlbumDialog(activity, object : PickAlbumDialog.OnPickAlbumListener { override fun onSuccess(path: String) { destinationPath = path - view.destination.text = context.humanizePath(path) + view.destination.text = activity.humanizePath(path) } }) } - AlertDialog.Builder(context) - .setTitle(context.resources.getString(if (files.size == 1) R.string.copy_item else R.string.copy_items)) + AlertDialog.Builder(activity) + .setTitle(activity.resources.getString(if (files.size == 1) R.string.copy_item else R.string.copy_items)) .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt index 6e6049d8b..f9a096da3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickAlbumDialog.kt @@ -12,23 +12,22 @@ import kotlinx.android.synthetic.main.dialog_album_picker.view.* import java.util.* class PickAlbumDialog(val activity: SimpleActivity, val listener: OnPickAlbumListener) : GetDirectoriesAsynctask.GetDirectoriesListener { - val context = activity.applicationContext var dialog: AlertDialog var directoriesGrid: RecyclerView init { - val view = LayoutInflater.from(context).inflate(R.layout.dialog_album_picker, null) + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_album_picker, null) directoriesGrid = view.directories_grid dialog = AlertDialog.Builder(activity) - .setTitle(context.resources.getString(R.string.select_destination)) + .setTitle(activity.resources.getString(R.string.select_destination)) .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create() dialog.show() - GetDirectoriesAsynctask(context, false, false, ArrayList(), this).execute() + GetDirectoriesAsynctask(activity, false, false, ArrayList(), this).execute() } override fun gotDirectories(dirs: ArrayList) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt index 63674f3dd..c177e86d4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameDirectoryDialog.kt @@ -12,16 +12,14 @@ import java.io.File import java.util.* class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val listener: OnRenameDirListener) { - val context = activity - init { - val view = LayoutInflater.from(context).inflate(R.layout.rename_directory, null) + val view = LayoutInflater.from(activity).inflate(R.layout.rename_directory, null) view.directory_name.setText(dir.name) - view.directory_path.text = "${context.humanizePath(dir.parent)}/" + view.directory_path.text = "${activity.humanizePath(dir.parent)}/" - AlertDialog.Builder(context) - .setTitle(context.resources.getString(R.string.rename_folder)) + AlertDialog.Builder(activity) + .setTitle(activity.resources.getString(R.string.rename_folder)) .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) @@ -30,12 +28,16 @@ class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val lis show() getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({ val newDirName = view.directory_name.value - if (newDirName.isEmpty()) { context.toast(R.string.rename_folder_empty) return@setOnClickListener } + if (!newDirName.isAValidFilename()) { + context.toast(R.string.invalid_name) + return@setOnClickListener + } + val updatedFiles = ArrayList() updatedFiles.add(dir.absolutePath) val newDir = File(dir.parent, newDirName) @@ -65,7 +67,7 @@ class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val lis } private fun sendSuccess(updatedFiles: ArrayList, newDir: File) { - context.toast(R.string.renaming_folder) + activity.toast(R.string.renaming_folder) val files = newDir.listFiles() files.mapTo(updatedFiles) { it.absolutePath } 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 fe2e0ca69..4471ba94d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/RenameFileDialog.kt @@ -13,8 +13,7 @@ import java.io.File class RenameFileDialog(val activity: SimpleActivity, val file: File, val listener: OnRenameFileListener) { init { - val context = activity - val view = LayoutInflater.from(context).inflate(R.layout.rename_file, null) + val view = LayoutInflater.from(activity).inflate(R.layout.rename_file, null) val fullName = file.name val dotAt = fullName.lastIndexOf(".") var name = fullName @@ -26,10 +25,10 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val listene } view.file_name.setText(name) - view.file_path.text = "${context.humanizePath(file.parent)}/" + view.file_path.text = "${activity.humanizePath(file.parent)}/" - AlertDialog.Builder(context) - .setTitle(context.resources.getString(R.string.rename_file)) + AlertDialog.Builder(activity) + .setTitle(activity.resources.getString(R.string.rename_file)) .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) @@ -45,6 +44,11 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val listene return@setOnClickListener } + if (!fileName.isAValidFilename()) { + context.toast(R.string.invalid_name) + return@setOnClickListener + } + val newFile = File(file.parent, "$fileName.$extension") if (context.needsStupidWritePermissions(file.absolutePath)) { 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 f397ffb42..359f8b84f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -14,12 +14,11 @@ import kotlinx.android.synthetic.main.rename_file.view.* class SaveAsDialog(val activity: Activity, val path: String, val listener: OnSaveAsListener) { init { - val context = activity - val view = LayoutInflater.from(context).inflate(R.layout.dialog_save_as, null) + val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null) view.file_name.setText(path.getFilenameFromPath()) - AlertDialog.Builder(context) - .setTitle(context.resources.getString(R.string.save_as)) + AlertDialog.Builder(activity) + .setTitle(activity.resources.getString(R.string.save_as)) .setView(view) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 897197e9f..a5db65d4f 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + Der Name enthält nicht erlaubte Zeichen 1 Ordner gelöscht diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index de44644e3..91058b2c7 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + The name contains invalid characters 1 carpeta eliminada diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 88f6cb67f..e0e4ed7e5 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + Il nome contiene caratteri non validi 1 cartella eliminata diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index b7164b390..bedd6d027 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + 名前に無効な文字が含まれています 1 フォルダーを削除しました diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 332e71a04..baecb19eb 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -60,6 +60,7 @@ Já existe um ficheiro com este nome Alguns ficheiros não foram movidos Alguns ficheiros não foram copiados + O nome contém caracteres inválidos 1 pasta apagada diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 1f148e01a..848ba522b 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + Namnet innehåller ogiltiga tecken 1 mapp borttagen diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index a5b9b5c00..2f4e15740 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -61,6 +61,7 @@ 相同的文件名已经存在 相同文件不能移动 相同文件不能复制 + The name contains invalid characters 1 folder deleted diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 42eca6dcd..179d12b24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -60,6 +60,7 @@ A file with that name already exists Some files could not be moved Some files could not be copied + The name contains invalid characters 1 folder deleted