fix #204, allow saving files without an extension

This commit is contained in:
tibbi 2018-03-31 10:55:04 +02:00
parent 73afe2caff
commit ada298017b
4 changed files with 74 additions and 78 deletions

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.View import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@ -36,7 +35,7 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this, R.string.compress_as) { activity.setupDialogStuff(view, this, R.string.compress_as) {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) showKeyboard(view.file_name)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.file_name.value val name = view.file_name.value
when { when {

View File

@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.View import android.view.View
import android.view.WindowManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.R import com.simplemobiletools.filemanager.R
@ -19,7 +18,7 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
activity.setupDialogStuff(view, this, R.string.create_new) { activity.setupDialogStuff(view, this, R.string.create_new) {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE) showKeyboard(view.item_name)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
val name = view.item_name.value val name = view.item_name.value
if (name.isEmpty()) { if (name.isEmpty()) {

View File

@ -1,7 +1,6 @@
package com.simplemobiletools.filemanager.dialogs package com.simplemobiletools.filemanager.dialogs
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.view.WindowManager
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -43,8 +42,8 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.create().apply { .create().apply {
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
activity.setupDialogStuff(view, this, R.string.save_as) { activity.setupDialogStuff(view, this, R.string.save_as) {
showKeyboard(view.save_as_name)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val filename = view.save_as_name.value val filename = view.save_as_name.value
val extension = view.save_as_extension.value val extension = view.save_as_extension.value
@ -54,12 +53,11 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
return@setOnClickListener return@setOnClickListener
} }
if (extension.isEmpty()) { var newFilename = filename
activity.toast(R.string.extension_cannot_be_empty) if (extension.isNotEmpty()) {
return@setOnClickListener newFilename += ".$extension"
} }
val newFilename = "$filename.$extension"
val newPath = "$realPath/$newFilename" val newPath = "$realPath/$newFilename"
if (!newFilename.isAValidFilename()) { if (!newFilename.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters) activity.toast(R.string.filename_invalid_characters)