diff options
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java | 25 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 6 |
2 files changed, 20 insertions, 11 deletions
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 88d60dfa..dfade7c1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -250,20 +250,27 @@ public class ParsePost { try { String k = it.next(); JSONObject media = mediaMetadataJSON.getJSONObject(k); - JSONArray downscales = media.getJSONArray(JSONUtils.P_KEY); - JSONObject downscaledItemJSON; - if (downscales.length() <= 3) { - downscaledItemJSON = downscales.getJSONObject(downscales.length() - 1); - } else { - downscaledItemJSON = downscales.getJSONObject(3); - } - MediaMetadata.MediaItem downscaledItem = new MediaMetadata.MediaItem(downscaledItemJSON.getInt(JSONUtils.X_KEY), - downscaledItemJSON.getInt(JSONUtils.Y_KEY), downscaledItemJSON.getString(JSONUtils.U_KEY)); JSONObject originalItemJSON = media.getJSONObject(JSONUtils.S_KEY); MediaMetadata.MediaItem originalItem = new MediaMetadata.MediaItem(originalItemJSON.getInt(JSONUtils.X_KEY), originalItemJSON.getInt(JSONUtils.Y_KEY), originalItemJSON.getString(JSONUtils.U_KEY)); + JSONArray downscales = media.getJSONArray(JSONUtils.P_KEY); + JSONObject downscaledItemJSON; + MediaMetadata.MediaItem downscaledItem; + if (downscales.length() <= 0) { + downscaledItem = originalItem; + } else { + if (downscales.length() <= 3) { + downscaledItemJSON = downscales.getJSONObject(downscales.length() - 1); + + } else { + downscaledItemJSON = downscales.getJSONObject(3); + } + downscaledItem = new MediaMetadata.MediaItem(downscaledItemJSON.getInt(JSONUtils.X_KEY), + downscaledItemJSON.getInt(JSONUtils.Y_KEY), downscaledItemJSON.getString(JSONUtils.U_KEY)); + } + String id = media.getString(JSONUtils.ID_KEY); mediaMetadataMap.put(id, new MediaMetadata(id, media.getString(JSONUtils.E_KEY), originalItem, downscaledItem)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java index 01ec20ac..c47c879a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -99,8 +99,9 @@ public final class Utils { int start = 0; int previewReddItLength = "https://preview.redd.it/".length(); while (matcher.find(start)) { - String id = markdownStringBuilder.substring(previewReddItLength, markdownStringBuilder.indexOf(".", previewReddItLength)); + String id = markdownStringBuilder.substring(matcher.start() + previewReddItLength, markdownStringBuilder.indexOf(".", matcher.start() + previewReddItLength)); if (!mediaMetadataMap.containsKey(id)) { + start = matcher.end(); continue; } String replacingText = "![img](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")"; @@ -114,8 +115,9 @@ public final class Utils { matcher = iReddItImagePattern.matcher(markdownStringBuilder); int iReddItLength = "https://i.redd.it/".length(); while (matcher.find(start)) { - String id = markdownStringBuilder.substring(iReddItLength, markdownStringBuilder.indexOf(".", iReddItLength)); + String id = markdownStringBuilder.substring(matcher.start() + iReddItLength, matcher.start() + markdownStringBuilder.indexOf(".", iReddItLength)); if (!mediaMetadataMap.containsKey(id)) { + start = matcher.end(); continue; } String replacingText = "![img](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")"; |