From 3249e9b2bcf4d15ba1216a9b54f2e5f0b3d62a31 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 27 Feb 2018 20:09:02 +0100 Subject: [PATCH] fix some crashes related to saving files --- .../draw/activities/MainActivity.kt | 8 ++++++-- .../kotlin/com/simplemobiletools/draw/models/Svg.kt | 12 ++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt index 28873b8..9c39a63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/activities/MainActivity.kt @@ -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!!) - toast(R.string.file_saved) + if (it != null) { + writeToOutputStream(path, it) + toast(R.string.file_saved) + } else { + toast(R.string.unknown_error_occurred) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/draw/models/Svg.kt b/app/src/main/kotlin/com/simplemobiletools/draw/models/Svg.kt index fe18952..2d2cf27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/draw/models/Svg.kt +++ b/app/src/main/kotlin/com/simplemobiletools/draw/models/Svg.kt @@ -21,10 +21,14 @@ object Svg { val backgroundColor = (canvas.background as ColorDrawable).color activity.getFileOutputStream(FileDirItem(path, path.getFilenameFromPath()), true) { - val writer = BufferedWriter(OutputStreamWriter(it)) - writeSvg(writer, backgroundColor, canvas.mPaths, canvas.width, canvas.height) - writer.close() - activity.toast(R.string.file_saved) + 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) + } } }