save the images on a background thread
This commit is contained in:
parent
972916f6b2
commit
4786fc7c54
1 changed files with 20 additions and 18 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue