mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
check if new file/dir names are valid
This commit is contained in:
parent
83dc85e63b
commit
fa4cadebb4
13 changed files with 38 additions and 27 deletions
|
@ -19,24 +19,23 @@ import java.util.*
|
|||
class CopyDialog(val activity: SimpleActivity, val files: ArrayList<File>, 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)
|
||||
|
|
|
@ -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<String>(), this).execute()
|
||||
GetDirectoriesAsynctask(activity, false, false, ArrayList<String>(), this).execute()
|
||||
}
|
||||
|
||||
override fun gotDirectories(dirs: ArrayList<Directory>) {
|
||||
|
|
|
@ -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<String>()
|
||||
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<String>, newDir: File) {
|
||||
context.toast(R.string.renaming_folder)
|
||||
activity.toast(R.string.renaming_folder)
|
||||
val files = newDir.listFiles()
|
||||
files.mapTo(updatedFiles) { it.absolutePath }
|
||||
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">Der Name enthält nicht erlaubte Zeichen</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 Ordner gelöscht</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">The name contains invalid characters</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 carpeta eliminada</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">Il nome contiene caratteri non validi</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 cartella eliminata</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">名前に無効な文字が含まれています</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 フォルダーを削除しました</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">Já existe um ficheiro com este nome</string>
|
||||
<string name="moving_success_partial">Alguns ficheiros não foram movidos</string>
|
||||
<string name="copying_success_partial">Alguns ficheiros não foram copiados</string>
|
||||
<string name="invalid_name">O nome contém caracteres inválidos</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 pasta apagada</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">Namnet innehåller ogiltiga tecken</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 mapp borttagen</item>
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
<string name="already_exists">相同的文件名已经存在</string>
|
||||
<string name="moving_success_partial">相同文件不能移动</string>
|
||||
<string name="copying_success_partial">相同文件不能复制</string>
|
||||
<string name="invalid_name">The name contains invalid characters</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 folder deleted</item>
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
<string name="already_exists">A file with that name already exists</string>
|
||||
<string name="moving_success_partial">Some files could not be moved</string>
|
||||
<string name="copying_success_partial">Some files could not be copied</string>
|
||||
<string name="invalid_name">The name contains invalid characters</string>
|
||||
|
||||
<plurals name="folders_deleted">
|
||||
<item quantity="one">1 folder deleted</item>
|
||||
|
|
Loading…
Reference in a new issue