From a2b57d66629aca5035cd60d47055659e8e9d5aea Mon Sep 17 00:00:00 2001 From: Yaron Budowski Date: Thu, 24 Oct 2024 13:31:34 +0200 Subject: [PATCH] Fix #1369 - crash fix; crash fix when trying to import photo, reading EXIF (for rotation) and file is unavailable --- iNaturalist/src/main/AndroidManifest.xml | 4 ++-- .../org/inaturalist/android/ImageUtils.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/iNaturalist/src/main/AndroidManifest.xml b/iNaturalist/src/main/AndroidManifest.xml index 5fd73b6f..a95ce717 100644 --- a/iNaturalist/src/main/AndroidManifest.xml +++ b/iNaturalist/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ + android:versionCode="617" + android:versionName="1.35.3"> diff --git a/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java b/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java index 41633d19..e244b0d1 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/ImageUtils.java @@ -1,5 +1,6 @@ package org.inaturalist.android; +import android.app.Activity; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; @@ -74,6 +75,13 @@ public class ImageUtils { public static void blur(Context context, Bitmap image, ImageView imageView) { if (null == image) return; + if (context == null) return; + if (context instanceof Activity) { + Activity activity = (Activity) context; + if (activity.isDestroyed() || activity.isFinishing()) { + return; // Avoid loading if activity is destroyed or finishing + } + } Glide.with(context) .asBitmap() @@ -402,9 +410,14 @@ public static String resizeImage(Context context, String path, Uri photoUri, int if (path != null) { - androidx.exifinterface.media.ExifInterface exif = new androidx.exifinterface.media.ExifInterface(path); - rotationDegrees = exif.getRotationDegrees(); - Logger.tag(TAG).error("resizeImage: degrees: " + rotationDegrees); + try { + androidx.exifinterface.media.ExifInterface exif = new androidx.exifinterface.media.ExifInterface(path); + rotationDegrees = exif.getRotationDegrees(); + Logger.tag(TAG).info("resizeImage: degrees: " + rotationDegrees); + } catch (Exception exc) { + Logger.tag(TAG).error("resizeImage: exception while reading rotation"); + Logger.tag(TAG).error(exc); + } } if (photoUri != null) {