mirror of
https://github.com/SimpleMobileTools/Simple-Draw.git
synced 2025-06-05 21:59:17 +02:00
tweak the SaveImageDialog, make it more flexible
This commit is contained in:
@ -369,13 +369,12 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveImage() {
|
private fun saveImage() {
|
||||||
SaveImageDialog(this, defaultExtension, defaultPath, defaultFilename) {
|
SaveImageDialog(this, defaultPath, defaultFilename, defaultExtension, false) { fullPath, filename, extension ->
|
||||||
savedPathsHash = my_canvas.getDrawingHashCode()
|
savedPathsHash = my_canvas.getDrawingHashCode()
|
||||||
saveFile(it)
|
saveFile(fullPath)
|
||||||
defaultPath = it.getParentPath()
|
defaultPath = fullPath.getParentPath()
|
||||||
defaultFilename = it.getFilenameFromPath()
|
defaultFilename = filename
|
||||||
defaultFilename = defaultFilename.substring(0, defaultFilename.lastIndexOf("."))
|
defaultExtension = extension
|
||||||
defaultExtension = it.getFilenameExtension()
|
|
||||||
config.lastSaveFolder = defaultPath
|
config.lastSaveFolder = defaultPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ import com.simplemobiletools.draw.pro.helpers.SVG
|
|||||||
import kotlinx.android.synthetic.main.dialog_save_image.view.*
|
import kotlinx.android.synthetic.main.dialog_save_image.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String, val defaultPath: String, val defaultFilename: String,
|
class SaveImageDialog(val activity: SimpleActivity, val defaultPath: String, val defaultFilename: String, val defaultExtension: String,
|
||||||
callback: (savePath: String) -> Unit) {
|
val hidePath: Boolean, callback: (fullPath: String, filename: String, extension: String) -> Unit) {
|
||||||
private val SIMPLE_DRAW = "Simple Draw"
|
private val SIMPLE_DRAW = "Simple Draw"
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -27,6 +27,10 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
|||||||
else -> R.id.save_image_radio_png
|
else -> R.id.save_image_radio_png
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (hidePath) {
|
||||||
|
save_image_path_label.beGone()
|
||||||
|
save_image_path.beGone()
|
||||||
|
} else {
|
||||||
save_image_path.text = activity.humanizePath(folder)
|
save_image_path.text = activity.humanizePath(folder)
|
||||||
save_image_path.setOnClickListener {
|
save_image_path.setOnClickListener {
|
||||||
FilePickerDialog(activity, folder, false, showFAB = true) {
|
FilePickerDialog(activity, folder, false, showFAB = true) {
|
||||||
@ -35,6 +39,7 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AlertDialog.Builder(activity)
|
AlertDialog.Builder(activity)
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
@ -64,11 +69,11 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
|||||||
if (File(newPath).exists()) {
|
if (File(newPath).exists()) {
|
||||||
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newPath.getFilenameFromPath())
|
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newPath.getFilenameFromPath())
|
||||||
ConfirmationDialog(activity, title) {
|
ConfirmationDialog(activity, title) {
|
||||||
callback(newPath)
|
callback(newPath, filename, extension)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
callback(newPath)
|
callback(newPath, filename, extension)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user