wrap the whole exif part of photofragment in try catch

This commit is contained in:
tibbi 2017-01-22 18:58:04 +01:00
parent 9773a481c8
commit 10670a8f0d

View file

@ -16,6 +16,7 @@ import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.getRealPathFromURI
import com.simplemobiletools.gallery.helpers.MEDIUM
@ -43,6 +44,8 @@ class PhotoFragment : ViewPagerFragment() {
medium.path = context.getRealPathFromURI(Uri.parse(medium.path)) ?: ""
if (medium.path.isEmpty()) {
var out: FileOutputStream? = null
try {
var inputStream = context.contentResolver.openInputStream(Uri.parse(originalPath))
val exif = ExifInterface()
exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL)
@ -56,19 +59,19 @@ class PhotoFragment : ViewPagerFragment() {
exif.removeCompressedThumbnail()
val file = File(context.externalCacheDir, Uri.parse(originalPath).lastPathSegment)
var out: FileOutputStream? = null
try {
out = FileOutputStream(file)
rotated.compress(Bitmap.CompressFormat.JPEG, 100, out)
exif.writeExif(rotated, file.absolutePath, 100)
medium.path = file.absolutePath
} catch (e: Exception) {
context.toast(R.string.unknown_error_occurred)
return view
} finally {
try {
out?.close()
} catch (e: IOException) {
}
}
exif.writeExif(rotated, file.absolutePath, 100)
medium.path = file.absolutePath
}
}