Skip to content

Commit

Permalink
#1327 - crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
budowski committed Jan 19, 2024
1 parent 508e14c commit 98e65d0
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,15 @@ public Object instantiateItem(ViewGroup container, final int position) {
if (mObsJson != null) {
try {
int obsPhotoCount = mObservation.photos != null ? mObservation.photos.size() : 0;
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;
JSONObject json = new JSONObject(mObsJson);
if (json.has("observation_sounds")) {
JSONArray obsSounds = json.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);
Expand All @@ -486,12 +489,15 @@ public Object instantiateItem(ViewGroup container, final int position) {

if (mObsJson != null) {
try {
JSONArray obsPhotos = new JSONObject(mObsJson).getJSONArray("observation_photos");

if (position < obsPhotos.length()) {
BetterJSONObject obsPhoto = new BetterJSONObject(obsPhotos.getJSONObject(position));
item = new BetterJSONObject(obsPhoto.getJSONObject("photo"));
isHidden = new ObservationPhoto(obsPhoto).hidden;
JSONObject json = new JSONObject(mObsJson);
if (json.has("observation_photos")) {
JSONArray obsPhotos = json.getJSONArray("observation_photos");

if (position < obsPhotos.length()) {
BetterJSONObject obsPhoto = new BetterJSONObject(obsPhotos.getJSONObject(position));
item = new BetterJSONObject(obsPhoto.getJSONObject("photo"));
isHidden = new ObservationPhoto(obsPhoto).hidden;
}
}
} catch (JSONException e) {
Logger.error(e);
Expand Down

0 comments on commit 98e65d0

Please sign in to comment.