From 39ae0d3aaf0eba042ca70e7fd67fcea0349af156 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 18 Jul 2020 00:22:07 +0800 Subject: Fix parsing Reddit gallery posts error when they contain a gif. Fix progress bar not showing in item_post_detail_gallery. --- .../ml/docilealligator/infinityforreddit/Post/ParsePost.java | 12 +++++++++++- .../docilealligator/infinityforreddit/Utils/JSONUtils.java | 1 + app/src/main/res/layout/item_post_detail_gallery.xml | 3 +-- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java index 17bb9bba..477cb697 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java @@ -398,7 +398,17 @@ public class ParsePost { String galleryId = galleryIdsArray.getJSONObject(i).getString(JSONUtils.MEDIA_ID_KEY); JSONObject singleGalleryObject = galleryObject.getJSONObject(galleryId); String mimeType = singleGalleryObject.getString(JSONUtils.M_KEY); - String galleryItemUrl = singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getString(JSONUtils.U_KEY); + String galleryItemUrl; + if (mimeType.contains("jpg") || mimeType.contains("png")) { + galleryItemUrl = singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getString(JSONUtils.U_KEY); + } else { + JSONObject sourceObject = singleGalleryObject.getJSONObject(JSONUtils.S_KEY); + if (mimeType.contains("gif")) { + galleryItemUrl = sourceObject.getString(JSONUtils.GIF_KEY); + } else { + galleryItemUrl = sourceObject.getString(JSONUtils.MP4_KEY); + } + } if ((previewUrl.equals("")) && mimeType.contains("jpg") || mimeType.contains("png")) { previewUrl = galleryItemUrl; post.setPreviewUrl(previewUrl); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index 1c47eb2a..1d9c876f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -122,4 +122,5 @@ public class JSONUtils { public static final String X_KEY = "x"; public static final String Y_KEY = "y"; public static final String DEST_KEY = "dest"; + public static final String GIF_KEY = "gif"; } diff --git a/app/src/main/res/layout/item_post_detail_gallery.xml b/app/src/main/res/layout/item_post_detail_gallery.xml index 05f013a1..8d2a9ce2 100644 --- a/app/src/main/res/layout/item_post_detail_gallery.xml +++ b/app/src/main/res/layout/item_post_detail_gallery.xml @@ -212,8 +212,7 @@ android:id="@+id/load_wrapper_item_post_detail_gallery" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_centerInParent="true" - android:visibility="gone"> + android:layout_centerInParent="true">