fix some crashes related to saving files

This commit is contained in:
tibbi 2018-02-27 20:09:02 +01:00
parent 73637c6305
commit 3249e9b2bc
2 changed files with 14 additions and 6 deletions

View File

@ -326,8 +326,12 @@ class MainActivity : SimpleActivity(), CanvasListener {
private fun saveImageFile(path: String) {
val fileDirItem = FileDirItem(path, path.getFilenameFromPath())
getFileOutputStream(fileDirItem, true) {
writeToOutputStream(path, it!!)
if (it != null) {
writeToOutputStream(path, it)
toast(R.string.file_saved)
} else {
toast(R.string.unknown_error_occurred)
}
}
}

View File

@ -21,10 +21,14 @@ object Svg {
val backgroundColor = (canvas.background as ColorDrawable).color
activity.getFileOutputStream(FileDirItem(path, path.getFilenameFromPath()), true) {
if (it != null) {
val writer = BufferedWriter(OutputStreamWriter(it))
writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height)
writer.close()
activity.toast(R.string.file_saved)
} else {
activity.toast(R.string.unknown_error_occurred)
}
}
}