Adding handleSAFDialog for EXIF rotation

This commit is contained in:
Guillaume 2017-11-07 23:08:20 +01:00 committed by GitHub
parent fef04593ac
commit 9a90787dbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -458,39 +458,41 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
Thread({ Thread({
toast(R.string.saving) toast(R.string.saving)
val selectedFile = File(it) val selectedFile = File(it)
val tmpFile = File(filesDir, ".tmp_${it.getFilenameFromPath()}") handleSAFDialog(selectedFile) {
try { val tmpFile = File(filesDir, ".tmp_${it.getFilenameFromPath()}")
val bitmap = BitmapFactory.decodeFile(currPath) try {
getFileOutputStream(tmpFile) { val bitmap = BitmapFactory.decodeFile(currPath)
if (it == null) { getFileOutputStream(tmpFile) {
toast(R.string.unknown_error_occurred) if (it == null) {
return@getFileOutputStream toast(R.string.unknown_error_occurred)
} return@getFileOutputStream
}
if (currPath.isJpg()) { if (currPath.isJpg()) {
saveRotation(getCurrentFile(), tmpFile) saveRotation(getCurrentFile(), tmpFile)
} else { } else {
saveFile(tmpFile, bitmap, it as FileOutputStream) saveFile(tmpFile, bitmap, it as FileOutputStream)
} }
if (tmpFile.length() > 0 && selectedFile.exists()) { if (tmpFile.length() > 0 && selectedFile.exists()) {
deleteFile(selectedFile) {} deleteFile(selectedFile) {}
} }
copyFile(tmpFile, selectedFile) copyFile(tmpFile, selectedFile)
scanPath(selectedFile.absolutePath) {} scanPath(selectedFile.absolutePath) {}
toast(R.string.file_saved) toast(R.string.file_saved)
it.flush() it.flush()
it.close() it.close()
mRotationDegrees = 0f mRotationDegrees = 0f
invalidateOptionsMenu() invalidateOptionsMenu()
}
} catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error)
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile) {}
} }
} catch (e: OutOfMemoryError) {
toast(R.string.out_of_memory_error)
} catch (e: Exception) {
showErrorToast(e)
} finally {
deleteFile(tmpFile) {}
} }
}).start() }).start()
} }