fix #204, allow saving files without an extension
This commit is contained in:
parent
73afe2caff
commit
ada298017b
|
@ -20,8 +20,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "
|
|||
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||
}
|
||||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||
}
|
||||
|
||||
currSorting = config.getFolderSorting(path)
|
||||
setupSortRadio()
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
|
|||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
|
@ -35,26 +34,26 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
|
|||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.compress_as) {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
||||
val name = view.file_name.value
|
||||
when {
|
||||
name.isEmpty() -> activity.toast(R.string.empty_name)
|
||||
name.isAValidFilename() -> {
|
||||
val newPath = "$realPath/$name.zip"
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
activity.toast(R.string.name_taken)
|
||||
return@OnClickListener
|
||||
}
|
||||
activity.setupDialogStuff(view, this, R.string.compress_as) {
|
||||
showKeyboard(view.file_name)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
||||
val name = view.file_name.value
|
||||
when {
|
||||
name.isEmpty() -> activity.toast(R.string.empty_name)
|
||||
name.isAValidFilename() -> {
|
||||
val newPath = "$realPath/$name.zip"
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
activity.toast(R.string.name_taken)
|
||||
return@OnClickListener
|
||||
}
|
||||
|
||||
dismiss()
|
||||
callback(newPath)
|
||||
}
|
||||
else -> activity.toast(R.string.invalid_name)
|
||||
dismiss()
|
||||
callback(newPath)
|
||||
}
|
||||
else -> activity.toast(R.string.invalid_name)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
|
|||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.filemanager.R
|
||||
|
@ -18,34 +17,34 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
|
|||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.create_new) {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
||||
val name = view.item_name.value
|
||||
if (name.isEmpty()) {
|
||||
activity.toast(R.string.empty_name)
|
||||
} else if (name.isAValidFilename()) {
|
||||
val newPath = "$path/$name"
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
activity.toast(R.string.name_taken)
|
||||
return@OnClickListener
|
||||
}
|
||||
activity.setupDialogStuff(view, this, R.string.create_new) {
|
||||
showKeyboard(view.item_name)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
|
||||
val name = view.item_name.value
|
||||
if (name.isEmpty()) {
|
||||
activity.toast(R.string.empty_name)
|
||||
} else if (name.isAValidFilename()) {
|
||||
val newPath = "$path/$name"
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
activity.toast(R.string.name_taken)
|
||||
return@OnClickListener
|
||||
}
|
||||
|
||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
|
||||
createDirectory(newPath, this) {
|
||||
callback(it)
|
||||
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
|
||||
createDirectory(newPath, this) {
|
||||
callback(it)
|
||||
}
|
||||
} else {
|
||||
createFile(newPath, this) {
|
||||
callback(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.invalid_name)
|
||||
}
|
||||
} else {
|
||||
createFile(newPath, this) {
|
||||
callback(it)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.invalid_name)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.simplemobiletools.filemanager.dialogs
|
||||
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
|
@ -43,41 +42,40 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
|
|||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
activity.setupDialogStuff(view, this, R.string.save_as) {
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val filename = view.save_as_name.value
|
||||
val extension = view.save_as_extension.value
|
||||
activity.setupDialogStuff(view, this, R.string.save_as) {
|
||||
showKeyboard(view.save_as_name)
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val filename = view.save_as_name.value
|
||||
val extension = view.save_as_extension.value
|
||||
|
||||
if (filename.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
}
|
||||
if (filename.isEmpty()) {
|
||||
activity.toast(R.string.filename_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (extension.isEmpty()) {
|
||||
activity.toast(R.string.extension_cannot_be_empty)
|
||||
return@setOnClickListener
|
||||
}
|
||||
var newFilename = filename
|
||||
if (extension.isNotEmpty()) {
|
||||
newFilename += ".$extension"
|
||||
}
|
||||
|
||||
val newFilename = "$filename.$extension"
|
||||
val newPath = "$realPath/$newFilename"
|
||||
if (!newFilename.isAValidFilename()) {
|
||||
activity.toast(R.string.filename_invalid_characters)
|
||||
return@setOnClickListener
|
||||
}
|
||||
val newPath = "$realPath/$newFilename"
|
||||
if (!newFilename.isAValidFilename()) {
|
||||
activity.toast(R.string.filename_invalid_characters)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
|
||||
ConfirmationDialog(activity, title) {
|
||||
callback(newPath)
|
||||
dismiss()
|
||||
if (activity.getDoesFilePathExist(newPath)) {
|
||||
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
|
||||
ConfirmationDialog(activity, title) {
|
||||
callback(newPath)
|
||||
dismiss()
|
||||
}
|
||||
} else {
|
||||
callback(newPath)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
callback(newPath)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue