save the images on a background thread

This commit is contained in:
tibbi 2017-04-24 22:56:24 +02:00
parent 972916f6b2
commit 4786fc7c54

View file

@ -232,27 +232,29 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun saveImageAs() { private fun saveImageAs() {
val currPath = getCurrentPath() val currPath = getCurrentPath()
SaveAsDialog(this, currPath) { SaveAsDialog(this, currPath) {
val selectedFile = File(it) Thread({
val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") val selectedFile = File(it)
try { val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}")
val bitmap = BitmapFactory.decodeFile(currPath) try {
getFileOutputStream(tmpFile) { val bitmap = BitmapFactory.decodeFile(currPath)
saveFile(tmpFile, bitmap, it) getFileOutputStream(tmpFile) {
if (needsStupidWritePermissions(selectedFile.absolutePath)) { saveFile(tmpFile, bitmap, it)
deleteFile(selectedFile) {} if (needsStupidWritePermissions(selectedFile.absolutePath)) {
} deleteFile(selectedFile) {}
}
renameFile(tmpFile, selectedFile) { renameFile(tmpFile, selectedFile) {
deleteFile(tmpFile) {} 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) { }).start()
toast(R.string.out_of_memory_error)
deleteFile(tmpFile) {}
} catch (e: Exception) {
toast(R.string.unknown_error_occurred)
deleteFile(tmpFile) {}
}
} }
} }