From cae852acc0f72a816d4bcc5e3365b79e03938f94 Mon Sep 17 00:00:00 2001 From: Yaron Budowski Date: Sun, 7 Jan 2024 17:42:41 -0600 Subject: [PATCH] #1320 - crash fix --- iNaturalist/src/main/AndroidManifest.xml | 4 ++-- .../inaturalist/android/ObservationViewerFragment.java | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/iNaturalist/src/main/AndroidManifest.xml b/iNaturalist/src/main/AndroidManifest.xml index 3e7a1c8fb..2c17952bd 100644 --- a/iNaturalist/src/main/AndroidManifest.xml +++ b/iNaturalist/src/main/AndroidManifest.xml @@ -3,8 +3,8 @@ xmlns:tools="http://schemas.android.com/tools" package="org.inaturalist.android" android:installLocation="auto" - android:versionCode="597" - android:versionName="1.30.4"> + android:versionCode="599" + android:versionName="1.30.6"> diff --git a/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java b/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java index c8889914c..ceb992a83 100644 --- a/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java +++ b/iNaturalist/src/main/java/org/inaturalist/android/ObservationViewerFragment.java @@ -463,9 +463,13 @@ public Object instantiateItem(ViewGroup container, final int position) { if (mObsJson != null) { try { int obsPhotoCount = mObservation.photos != null ? mObservation.photos.size() : 0; - BetterJSONObject obsSound = new BetterJSONObject(new JSONObject(mObsJson).getJSONArray("observation_sounds").getJSONObject(position - obsPhotoCount)); - item = new BetterJSONObject(obsSound.getJSONObject("sound")); - isHidden = new ObservationSound(obsSound).hidden; + JSONArray obsSounds = new JSONObject(mObsJson).getJSONArray("observation_sounds"); + + if ((position - obsPhotoCount < obsSounds.length()) && (position - obsPhotoCount >= 0)) { + BetterJSONObject obsSound = new BetterJSONObject(obsSounds.getJSONObject(position - obsPhotoCount)); + item = new BetterJSONObject(obsSound.getJSONObject("sound")); + isHidden = new ObservationSound(obsSound).hidden; + } } catch (JSONException e) { throw new RuntimeException(e); }