diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 990660a9c..0ef4f722f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -232,27 +232,29 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun saveImageAs() { val currPath = getCurrentPath() SaveAsDialog(this, currPath) { - val selectedFile = File(it) - val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") - try { - val bitmap = BitmapFactory.decodeFile(currPath) - getFileOutputStream(tmpFile) { - saveFile(tmpFile, bitmap, it) - if (needsStupidWritePermissions(selectedFile.absolutePath)) { - deleteFile(selectedFile) {} - } + Thread({ + val selectedFile = File(it) + val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") + try { + val bitmap = BitmapFactory.decodeFile(currPath) + getFileOutputStream(tmpFile) { + saveFile(tmpFile, bitmap, it) + if (needsStupidWritePermissions(selectedFile.absolutePath)) { + deleteFile(selectedFile) {} + } - renameFile(tmpFile, selectedFile) { - deleteFile(tmpFile) {} + renameFile(tmpFile, selectedFile) { + deleteFile(tmpFile) {} + } } + } catch (e: OutOfMemoryError) { + toast(R.string.out_of_memory_error) + deleteFile(tmpFile) {} + } catch (e: Exception) { + toast(R.string.unknown_error_occurred) + deleteFile(tmpFile) {} } - } catch (e: OutOfMemoryError) { - toast(R.string.out_of_memory_error) - deleteFile(tmpFile) {} - } catch (e: Exception) { - toast(R.string.unknown_error_occurred) - deleteFile(tmpFile) {} - } + }).start() } }