From ada298017bd95bec146b861c52f972f8c7e6c4ba Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 31 Mar 2018 10:55:04 +0200 Subject: [PATCH] fix #204, allow saving files without an extension --- .../dialogs/ChangeSortingDialog.kt | 4 +- .../filemanager/dialogs/CompressAsDialog.kt | 39 ++++++------- .../dialogs/CreateNewItemDialog.kt | 51 ++++++++-------- .../filemanager/dialogs/SaveAsDialog.kt | 58 +++++++++---------- 4 files changed, 74 insertions(+), 78 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/ChangeSortingDialog.kt index c8639e05..96ed956f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/ChangeSortingDialog.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt index 61fc6a65..c0828778 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt @@ -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) + } + }) } - }) - } - } + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt index 72b7440e..f1ef9329 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt @@ -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) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt index 08498e06..5d858a6c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt @@ -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() } } - } - } } }