adding a couple more checks at saving edited file

This commit is contained in:
tibbi 2017-04-24 22:14:09 +02:00
parent dfc99e68e4
commit f94c09a83c

View file

@ -232,18 +232,26 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun saveImageAs() { private fun saveImageAs() {
val currPath = getCurrentPath() val currPath = getCurrentPath()
SaveAsDialog(this, currPath) { SaveAsDialog(this, currPath) {
try {
val selectedFile = File(it) val selectedFile = File(it)
val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}") val tmpFile = File(selectedFile.parent, "tmp_${it.getFilenameFromPath()}")
try {
val bitmap = BitmapFactory.decodeFile(currPath) val bitmap = BitmapFactory.decodeFile(currPath)
getFileOutputStream(tmpFile) { getFileOutputStream(tmpFile) {
saveFile(tmpFile, bitmap, it) saveFile(tmpFile, bitmap, it)
renameFile(tmpFile, selectedFile) { } if (needsStupidWritePermissions(selectedFile.absolutePath)) {
deleteFile(selectedFile) {}
}
renameFile(tmpFile, selectedFile) {
deleteFile(tmpFile) {}
}
} }
} catch (e: OutOfMemoryError) { } catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error) toast(R.string.out_of_memory_error)
deleteFile(tmpFile) {}
} catch (e: Exception) { } catch (e: Exception) {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
deleteFile(tmpFile) {}
} }
} }
} }