replace File with path at saving images
This commit is contained in:
parent
a1eaa54d44
commit
c66256fbae
|
@ -59,14 +59,14 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
|||
else -> JPG
|
||||
}
|
||||
|
||||
val newFile = File(folder, "$filename.$extension")
|
||||
if (!newFile.name.isAValidFilename()) {
|
||||
val newPath = "$folder/$filename.$extension"
|
||||
if (!newPath.getFilenameFromPath().isAValidFilename()) {
|
||||
activity.toast(R.string.filename_invalid_characters)
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
if (saveFile(newFile)) {
|
||||
callback(newFile.absolutePath, extension)
|
||||
if (saveFile(newPath)) {
|
||||
callback(newPath, extension)
|
||||
dismiss()
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
|
@ -76,18 +76,18 @@ class SaveImageDialog(val activity: SimpleActivity, val defaultExtension: String
|
|||
}
|
||||
}
|
||||
|
||||
private fun saveFile(file: File): Boolean {
|
||||
if (!file.parentFile.exists()) {
|
||||
if (!file.parentFile.mkdir()) {
|
||||
private fun saveFile(path: String): Boolean {
|
||||
if (!activity.getDoesFilePathExist(path.getParentPath())) {
|
||||
if (!File(path).parentFile.mkdir()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
when (file.extension) {
|
||||
SVG -> Svg.saveSvg(activity, file, canvas)
|
||||
else -> saveImageFile(file.absolutePath)
|
||||
when (path.getFilenameExtension()) {
|
||||
SVG -> Svg.saveSvg(activity, path, canvas)
|
||||
else -> saveImageFile(path)
|
||||
}
|
||||
activity.scanFile(file) {}
|
||||
activity.scanPath(path) {}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ import android.net.Uri
|
|||
import android.sax.RootElement
|
||||
import android.util.Xml
|
||||
import com.simplemobiletools.commons.extensions.getFileOutputStream
|
||||
import com.simplemobiletools.commons.extensions.toFileDirItem
|
||||
import com.simplemobiletools.commons.extensions.getFilenameFromPath
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.models.FileDirItem
|
||||
import com.simplemobiletools.draw.R
|
||||
import com.simplemobiletools.draw.activities.MainActivity
|
||||
import com.simplemobiletools.draw.activities.SimpleActivity
|
||||
|
@ -16,10 +17,10 @@ import java.io.*
|
|||
import java.util.*
|
||||
|
||||
object Svg {
|
||||
fun saveSvg(activity: SimpleActivity, file: File, canvas: MyCanvas) {
|
||||
fun saveSvg(activity: SimpleActivity, path: String, canvas: MyCanvas) {
|
||||
val backgroundColor = (canvas.background as ColorDrawable).color
|
||||
|
||||
activity.getFileOutputStream(file.toFileDirItem(activity), true) {
|
||||
activity.getFileOutputStream(FileDirItem(path, path.getFilenameFromPath()), true) {
|
||||
val writer = BufferedWriter(OutputStreamWriter(it))
|
||||
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
|
||||
writer.close()
|
||||
|
|
Loading…
Reference in New Issue