split filename and extension at save dialog
This commit is contained in:
parent
ae927425aa
commit
6c5a428b40
12 changed files with 51 additions and 9 deletions
|
@ -37,20 +37,24 @@ class RenameFileDialog(val activity: SimpleActivity, val file: File, val callbac
|
||||||
setCanceledOnTouchOutside(true)
|
setCanceledOnTouchOutside(true)
|
||||||
show()
|
show()
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
||||||
val fileName = view.file_name.value
|
val filename = view.file_name.value
|
||||||
val extension = view.file_extension.value
|
val extension = view.file_extension.value
|
||||||
|
|
||||||
if (fileName.isEmpty() || extension.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
context.toast(R.string.filename_cannot_be_empty)
|
context.toast(R.string.filename_cannot_be_empty)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileName.isAValidFilename()) {
|
if (extension.isEmpty()) {
|
||||||
context.toast(R.string.invalid_name)
|
context.toast(R.string.extension_cannot_be_empty)
|
||||||
return@setOnClickListener
|
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 (context.needsStupidWritePermissions(file.absolutePath)) {
|
||||||
if (activity.isShowingPermDialog(file))
|
if (activity.isShowingPermDialog(file))
|
||||||
|
|
|
@ -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)
|
val view = LayoutInflater.from(activity).inflate(R.layout.dialog_save_as, null)
|
||||||
view.apply {
|
view.apply {
|
||||||
file_path.text = activity.humanizePath(realPath)
|
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 {
|
file_path.setOnClickListener {
|
||||||
FilePickerDialog(activity, realPath, false, false, listener = object : FilePickerDialog.OnFilePickerListener {
|
FilePickerDialog(activity, realPath, false, false, listener = object : FilePickerDialog.OnFilePickerListener {
|
||||||
override fun onSuccess(pickedPath: String) {
|
override fun onSuccess(pickedPath: String) {
|
||||||
|
@ -43,19 +53,25 @@ class SaveAsDialog(val activity: Activity, val path: String, val callback: (save
|
||||||
show()
|
show()
|
||||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener({
|
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()) {
|
if (filename.isEmpty()) {
|
||||||
context.toast(R.string.filename_cannot_be_empty)
|
context.toast(R.string.filename_cannot_be_empty)
|
||||||
return@setOnClickListener
|
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)
|
context.toast(R.string.filename_invalid_characters)
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
val newPath = File(realPath, filename).absolutePath
|
callback.invoke(newFile.absolutePath)
|
||||||
callback.invoke(newPath)
|
|
||||||
dismiss()
|
dismiss()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,4 +30,17 @@
|
||||||
android:layout_marginBottom="@dimen/activity_margin"
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
android:singleLine="true"/>
|
android:singleLine="true"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/file_extension_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/extension"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/file_extension"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="@dimen/activity_margin"
|
||||||
|
android:singleLine="true"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">Dateiname darf nicht leer sein</string>
|
<string name="filename_cannot_be_empty">Dateiname darf nicht leer sein</string>
|
||||||
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
||||||
<string name="extension">Dateiendung</string>
|
<string name="extension">Dateiendung</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Sortieren nach</string>
|
<string name="sort_by">Sortieren nach</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">El nombre de archivo no puede estar vacío</string>
|
<string name="filename_cannot_be_empty">El nombre de archivo no puede estar vacío</string>
|
||||||
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
||||||
<string name="extension">Extensión</string>
|
<string name="extension">Extensión</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Ordenar por</string>
|
<string name="sort_by">Ordenar por</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">Il nome del file non deve essere vuoto</string>
|
<string name="filename_cannot_be_empty">Il nome del file non deve essere vuoto</string>
|
||||||
<string name="filename_invalid_characters">Il nome contiene caratteri non validi</string>
|
<string name="filename_invalid_characters">Il nome contiene caratteri non validi</string>
|
||||||
<string name="extension">Estensione</string>
|
<string name="extension">Estensione</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Ordina per</string>
|
<string name="sort_by">Ordina per</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">ファイル名は空にできません</string>
|
<string name="filename_cannot_be_empty">ファイル名は空にできません</string>
|
||||||
<string name="filename_invalid_characters">ファイル名に無効な文字が含まれています</string>
|
<string name="filename_invalid_characters">ファイル名に無効な文字が含まれています</string>
|
||||||
<string name="extension">拡張</string>
|
<string name="extension">拡張</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">並び替え</string>
|
<string name="sort_by">並び替え</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">O nome do ficheiro não pode estar vazio</string>
|
<string name="filename_cannot_be_empty">O nome do ficheiro não pode estar vazio</string>
|
||||||
<string name="filename_invalid_characters">O nome do ficheiro contém caracteres inválidos</string>
|
<string name="filename_invalid_characters">O nome do ficheiro contém caracteres inválidos</string>
|
||||||
<string name="extension">Extensão</string>
|
<string name="extension">Extensão</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Ordenar por</string>
|
<string name="sort_by">Ordenar por</string>
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
<string name="filename_cannot_be_empty">Имя файла не может быть пустым</string>
|
<string name="filename_cannot_be_empty">Имя файла не может быть пустым</string>
|
||||||
<string name="filename_invalid_characters">Имя файла содержит недопустимые символы</string>
|
<string name="filename_invalid_characters">Имя файла содержит недопустимые символы</string>
|
||||||
<string name="extension">Расширение</string>
|
<string name="extension">Расширение</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Сортировать по</string>
|
<string name="sort_by">Сортировать по</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">Du måste ange ett filnamn</string>
|
<string name="filename_cannot_be_empty">Du måste ange ett filnamn</string>
|
||||||
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
||||||
<string name="extension">Filändelse</string>
|
<string name="extension">Filändelse</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Sort by</string>
|
<string name="sort_by">Sort by</string>
|
||||||
|
|
|
@ -82,6 +82,7 @@
|
||||||
<string name="filename_cannot_be_empty">文件名不能为空</string>
|
<string name="filename_cannot_be_empty">文件名不能为空</string>
|
||||||
<string name="filename_invalid_characters">文件名包含非法字符</string>
|
<string name="filename_invalid_characters">文件名包含非法字符</string>
|
||||||
<string name="extension">扩展名</string>
|
<string name="extension">扩展名</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">排序方式</string>
|
<string name="sort_by">排序方式</string>
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
<string name="filename_cannot_be_empty">Filename cannot be empty</string>
|
<string name="filename_cannot_be_empty">Filename cannot be empty</string>
|
||||||
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
<string name="filename_invalid_characters">Filename contains invalid characters</string>
|
||||||
<string name="extension">Extension</string>
|
<string name="extension">Extension</string>
|
||||||
|
<string name="extension_cannot_be_empty">Extension cannot be empty</string>
|
||||||
|
|
||||||
<!-- Sorting -->
|
<!-- Sorting -->
|
||||||
<string name="sort_by">Sort by</string>
|
<string name="sort_by">Sort by</string>
|
||||||
|
|
Loading…
Reference in a new issue