From d7673d887c74c92db1a2cae5b235bffdbdde1e86 Mon Sep 17 00:00:00 2001 From: Nathan Grennan Date: Thu, 19 Dec 2024 17:23:45 -0700 Subject: [PATCH] Improved giphy gifs using the preview if it is available --- .../SubmissionViews/HeaderImageLinkView.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/src/main/java/me/ccrama/redditslide/SubmissionViews/HeaderImageLinkView.java b/app/src/main/java/me/ccrama/redditslide/SubmissionViews/HeaderImageLinkView.java index b7a4fb229..fcdcf5ba8 100644 --- a/app/src/main/java/me/ccrama/redditslide/SubmissionViews/HeaderImageLinkView.java +++ b/app/src/main/java/me/ccrama/redditslide/SubmissionViews/HeaderImageLinkView.java @@ -257,6 +257,40 @@ public void doImageAndText(final Submission submission, boolean full, String bas thumbUsed = true; } loadedUrl = submission.getUrl(); + } else if (type == ContentType.Type.GIF) { + JsonNode dataNode = submission.getDataNode(); + + url = submission.getUrl(); + String redditPreviewUrl = null; + + // Check for preview data + if (dataNode.has("preview")) { + JsonNode previewNode = dataNode.get("preview").get("images"); + if (previewNode != null && previewNode.size() > 0) { + JsonNode sourceNode = previewNode.get(0).get("source"); + if (sourceNode != null && sourceNode.has("url")) { + redditPreviewUrl = sourceNode.get("url").asText(); + } + } + } + + // Use Reddit preview URL if available + if (redditPreviewUrl != null) { + url = redditPreviewUrl; + } + + // Load the URL + if (!full && !SettingValues.isPicsEnabled(baseSub)) { + thumbImage2.setVisibility(View.VISIBLE); + ((Reddit) getContext().getApplicationContext()).getImageLoader() + .displayImage(url, thumbImage2); + setVisibility(View.GONE); + } else { + backdrop.setVisibility(View.VISIBLE); + ((Reddit) getContext().getApplicationContext()).getImageLoader() + .displayImage(url, backdrop); + setVisibility(View.VISIBLE); + } } else if (type == ContentType.Type.REDDIT_GALLERY) { JsonNode dataNode = submission.getDataNode();