mirror of
				https://github.com/SimpleMobileTools/Simple-File-Manager.git
				synced 2025-06-05 22:09:15 +02:00 
			
		
		
		
	fix #204, allow saving files without an extension
This commit is contained in:
		| @@ -20,8 +20,8 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val path: String = " | |||||||
|                 .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) |                 .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) | ||||||
|                 .setNegativeButton(R.string.cancel, null) |                 .setNegativeButton(R.string.cancel, null) | ||||||
|                 .create().apply { |                 .create().apply { | ||||||
|             activity.setupDialogStuff(view, this, R.string.sort_by) |                     activity.setupDialogStuff(view, this, R.string.sort_by) | ||||||
|         } |                 } | ||||||
|  |  | ||||||
|         currSorting = config.getFolderSorting(path) |         currSorting = config.getFolderSorting(path) | ||||||
|         setupSortRadio() |         setupSortRadio() | ||||||
|   | |||||||
| @@ -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.* | ||||||
| @@ -35,26 +34,26 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c | |||||||
|                 .setPositiveButton(R.string.ok, null) |                 .setPositiveButton(R.string.ok, null) | ||||||
|                 .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 { | ||||||
|                         name.isEmpty() -> activity.toast(R.string.empty_name) |                                 name.isEmpty() -> activity.toast(R.string.empty_name) | ||||||
|                         name.isAValidFilename() -> { |                                 name.isAValidFilename() -> { | ||||||
|                             val newPath = "$realPath/$name.zip" |                                     val newPath = "$realPath/$name.zip" | ||||||
|                             if (activity.getDoesFilePathExist(newPath)) { |                                     if (activity.getDoesFilePathExist(newPath)) { | ||||||
|                                 activity.toast(R.string.name_taken) |                                         activity.toast(R.string.name_taken) | ||||||
|                                 return@OnClickListener |                                         return@OnClickListener | ||||||
|                             } |                                     } | ||||||
|  |  | ||||||
|                             dismiss() |                                     dismiss() | ||||||
|                             callback(newPath) |                                     callback(newPath) | ||||||
|                         } |                                 } | ||||||
|                         else -> activity.toast(R.string.invalid_name) |                                 else -> activity.toast(R.string.invalid_name) | ||||||
|  |                             } | ||||||
|  |                         }) | ||||||
|                     } |                     } | ||||||
|                 }) |                 } | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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 | ||||||
| @@ -18,34 +17,34 @@ class CreateNewItemDialog(val activity: BaseSimpleActivity, val path: String, va | |||||||
|                 .setPositiveButton(R.string.ok, null) |                 .setPositiveButton(R.string.ok, null) | ||||||
|                 .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()) { | ||||||
|                         activity.toast(R.string.empty_name) |                                 activity.toast(R.string.empty_name) | ||||||
|                     } else if (name.isAValidFilename()) { |                             } else if (name.isAValidFilename()) { | ||||||
|                         val newPath = "$path/$name" |                                 val newPath = "$path/$name" | ||||||
|                         if (activity.getDoesFilePathExist(newPath)) { |                                 if (activity.getDoesFilePathExist(newPath)) { | ||||||
|                             activity.toast(R.string.name_taken) |                                     activity.toast(R.string.name_taken) | ||||||
|                             return@OnClickListener |                                     return@OnClickListener | ||||||
|                         } |                                 } | ||||||
|  |  | ||||||
|                         if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) { |                                 if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_directory) { | ||||||
|                             createDirectory(newPath, this) { |                                     createDirectory(newPath, this) { | ||||||
|                                 callback(it) |                                         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) { |     private fun createDirectory(path: String, alertDialog: AlertDialog, callback: (Boolean) -> Unit) { | ||||||
|   | |||||||
| @@ -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,41 +42,40 @@ 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 | ||||||
|  |  | ||||||
|                     if (filename.isEmpty()) { |                             if (filename.isEmpty()) { | ||||||
|                         activity.toast(R.string.filename_cannot_be_empty) |                                 activity.toast(R.string.filename_cannot_be_empty) | ||||||
|                         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) |                                 return@setOnClickListener | ||||||
|                         return@setOnClickListener |                             } | ||||||
|                     } |  | ||||||
|  |  | ||||||
|                     if (activity.getDoesFilePathExist(newPath)) { |                             if (activity.getDoesFilePathExist(newPath)) { | ||||||
|                         val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) |                                 val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) | ||||||
|                         ConfirmationDialog(activity, title) { |                                 ConfirmationDialog(activity, title) { | ||||||
|                             callback(newPath) |                                     callback(newPath) | ||||||
|                             dismiss() |                                     dismiss() | ||||||
|  |                                 } | ||||||
|  |                             } else { | ||||||
|  |                                 callback(newPath) | ||||||
|  |                                 dismiss() | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } else { |  | ||||||
|                         callback(newPath) |  | ||||||
|                         dismiss() |  | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user