From 4786fc7c548da6d9bd390dbdebef1ee369ff2e49 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 24 Apr 2017 22:56:24 +0200 Subject: [PATCH] save the images on a background thread --- .../gallery/activities/ViewPagerActivity.kt | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) 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() } }