Skip to content

Commit ada2980

Browse files
committed
fix #204, allow saving files without an extension
1 parent 73afe2c commit ada2980

File tree

4 files changed

+74
-78
lines changed

4 files changed

+74
-78
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/ChangeSortingDialog.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = "
2020
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
2121
.setNegativeButton(R.string.cancel, null)
2222
.create().apply {
23-
activity.setupDialogStuff(view, this, R.string.sort_by)
24-
}
23+
activity.setupDialogStuff(view, this, R.string.sort_by)
24+
}
2525

2626
currSorting = config.getFolderSorting(path)
2727
setupSortRadio()

app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CompressAsDialog.kt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
22

33
import android.support.v7.app.AlertDialog
44
import android.view.View
5-
import android.view.WindowManager
65
import com.simplemobiletools.commons.activities.BaseSimpleActivity
76
import com.simplemobiletools.commons.dialogs.FilePickerDialog
87
import com.simplemobiletools.commons.extensions.*
@@ -35,26 +34,26 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
3534
.setPositiveButton(R.string.ok, null)
3635
.setNegativeButton(R.string.cancel, null)
3736
.create().apply {
38-
activity.setupDialogStuff(view, this, R.string.compress_as) {
39-
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
40-
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
41-
val name = view.file_name.value
42-
when {
43-
name.isEmpty() -> activity.toast(R.string.empty_name)
44-
name.isAValidFilename() -> {
45-
val newPath = "$realPath/$name.zip"
46-
if (activity.getDoesFilePathExist(newPath)) {
47-
activity.toast(R.string.name_taken)
48-
return@OnClickListener
49-
}
37+
activity.setupDialogStuff(view, this, R.string.compress_as) {
38+
showKeyboard(view.file_name)
39+
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
40+
val name = view.file_name.value
41+
when {
42+
name.isEmpty() -> activity.toast(R.string.empty_name)
43+
name.isAValidFilename() -> {
44+
val newPath = "$realPath/$name.zip"
45+
if (activity.getDoesFilePathExist(newPath)) {
46+
activity.toast(R.string.name_taken)
47+
return@OnClickListener
48+
}
5049

51-
dismiss()
52-
callback(newPath)
53-
}
54-
else -> activity.toast(R.string.invalid_name)
50+
dismiss()
51+
callback(newPath)
52+
}
53+
else -> activity.toast(R.string.invalid_name)
54+
}
55+
})
5556
}
56-
})
57-
}
58-
}
57+
}
5958
}
6059
}

app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/CreateNewItemDialog.kt

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.simplemobiletools.filemanager.dialogs
22

33
import android.support.v7.app.AlertDialog
44
import android.view.View
5-
import android.view.WindowManager
65
import com.simplemobiletools.commons.activities.BaseSimpleActivity
76
import com.simplemobiletools.commons.extensions.*
87
import com.simplemobiletools.filemanager.R
@@ -18,34 +17,34 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va
1817
.setPositiveButton(R.string.ok, null)
1918
.setNegativeButton(R.string.cancel, null)
2019
.create().apply {
21-
activity.setupDialogStuff(view, this, R.string.create_new) {
22-
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
23-
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
24-
val name = view.item_name.value
25-
if (name.isEmpty()) {
26-
activity.toast(R.string.empty_name)
27-
} else if (name.isAValidFilename()) {
28-
val newPath = "$path/$name"
29-
if (activity.getDoesFilePathExist(newPath)) {
30-
activity.toast(R.string.name_taken)
31-
return@OnClickListener
32-
}
20+
activity.setupDialogStuff(view, this, R.string.create_new) {
21+
showKeyboard(view.item_name)
22+
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(View.OnClickListener {
23+
val name = view.item_name.value
24+
if (name.isEmpty()) {
25+
activity.toast(R.string.empty_name)
26+
} else if (name.isAValidFilename()) {
27+
val newPath = "$path/$name"
28+
if (activity.getDoesFilePathExist(newPath)) {
29+
activity.toast(R.string.name_taken)
30+
return@OnClickListener
31+
}
3332

34-
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
35-
createDirectory(newPath, this) {
36-
callback(it)
33+
if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) {
34+
createDirectory(newPath, this) {
35+
callback(it)
36+
}
37+
} else {
38+
createFile(newPath, this) {
39+
callback(it)
40+
}
41+
}
42+
} else {
43+
activity.toast(R.string.invalid_name)
3744
}
38-
} else {
39-
createFile(newPath, this) {
40-
callback(it)
41-
}
42-
}
43-
} else {
44-
activity.toast(R.string.invalid_name)
45+
})
4546
}
46-
})
47-
}
48-
}
47+
}
4948
}
5049

5150
private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) {

app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/SaveAsDialog.kt

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.simplemobiletools.filemanager.dialogs
22

33
import android.support.v7.app.AlertDialog
4-
import android.view.WindowManager
54
import com.simplemobiletools.commons.activities.BaseSimpleActivity
65
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
76
import com.simplemobiletools.commons.dialogs.FilePickerDialog
@@ -43,41 +42,40 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
4342
.setPositiveButton(R.string.ok, null)
4443
.setNegativeButton(R.string.cancel, null)
4544
.create().apply {
46-
window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
47-
activity.setupDialogStuff(view, this, R.string.save_as) {
48-
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
49-
val filename = view.save_as_name.value
50-
val extension = view.save_as_extension.value
45+
activity.setupDialogStuff(view, this, R.string.save_as) {
46+
showKeyboard(view.save_as_name)
47+
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
48+
val filename = view.save_as_name.value
49+
val extension = view.save_as_extension.value
5150

52-
if (filename.isEmpty()) {
53-
activity.toast(R.string.filename_cannot_be_empty)
54-
return@setOnClickListener
55-
}
51+
if (filename.isEmpty()) {
52+
activity.toast(R.string.filename_cannot_be_empty)
53+
return@setOnClickListener
54+
}
5655

57-
if (extension.isEmpty()) {
58-
activity.toast(R.string.extension_cannot_be_empty)
59-
return@setOnClickListener
60-
}
56+
var newFilename = filename
57+
if (extension.isNotEmpty()) {
58+
newFilename += ".$extension"
59+
}
6160

62-
val newFilename = "$filename.$extension"
63-
val newPath = "$realPath/$newFilename"
64-
if (!newFilename.isAValidFilename()) {
65-
activity.toast(R.string.filename_invalid_characters)
66-
return@setOnClickListener
67-
}
61+
val newPath = "$realPath/$newFilename"
62+
if (!newFilename.isAValidFilename()) {
63+
activity.toast(R.string.filename_invalid_characters)
64+
return@setOnClickListener
65+
}
6866

69-
if (activity.getDoesFilePathExist(newPath)) {
70-
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
71-
ConfirmationDialog(activity, title) {
72-
callback(newPath)
73-
dismiss()
67+
if (activity.getDoesFilePathExist(newPath)) {
68+
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
69+
ConfirmationDialog(activity, title) {
70+
callback(newPath)
71+
dismiss()
72+
}
73+
} else {
74+
callback(newPath)
75+
dismiss()
76+
}
7477
}
75-
} else {
76-
callback(newPath)
77-
dismiss()
7878
}
7979
}
80-
}
81-
}
8280
}
8381
}

0 commit comments

Comments
 (0)