From b8e2d44638b0ecb213fb0fa74c17da0060f4fd31 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:11:02 +0300 Subject: Initial support for gallery captions --- .../adapters/PostDetailRecyclerViewAdapter.java | 24 ++++++++++ .../ViewRedditGalleryImageOrGifFragment.java | 52 +++++++++++++++++++++- .../infinityforreddit/post/FetchRemovedPost.java | 2 +- .../infinityforreddit/post/ParsePost.java | 31 +++++++++---- .../infinityforreddit/post/Post.java | 32 ++++++++++++- .../infinityforreddit/utils/JSONUtils.java | 2 + 6 files changed, 129 insertions(+), 14 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index 789ce798..3d481524 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -810,6 +810,24 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { + UrlMenuBottomSheetFragment urlMenuBottomSheetFragment = new UrlMenuBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(UrlMenuBottomSheetFragment.EXTRA_URL, captionUrl); + urlMenuBottomSheetFragment.setArguments(bundle); + urlMenuBottomSheetFragment.show(activity.getSupportFragmentManager(), urlMenuBottomSheetFragment.getTag()); + return true; + }); + + captionUrlTextView.setVisibility(View.VISIBLE); + captionUrlTextView.setText(captionUrl); + } + } + return rootView; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java index 8ae15029..e49ffa7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/FetchRemovedPost.java @@ -98,7 +98,7 @@ public class FetchRemovedPost { previews.set(0, preview); } } else { - Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1); + Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1, "", ""); preview.setPreviewUrl(result.getString("thumbnail")); ArrayList newPreviews = new ArrayList<>(); newPreviews.add(preview); 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 ff341041..860feaf2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -209,7 +209,7 @@ public class ParsePost { String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY); int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight)); + previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight, "", "")); JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY); for (int i = 0; i < thumbnailPreviews.length(); i++) { @@ -218,7 +218,7 @@ public class ParsePost { int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY); int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight)); + previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight, "", "")); } } if (data.has(JSONUtils.CROSSPOST_PARENT_LIST)) { @@ -301,7 +301,7 @@ public class ParsePost { spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else { @@ -341,7 +341,7 @@ public class ParsePost { String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY); int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY); int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight)); + previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight, "", "")); JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY); for (int i = 0; i < thumbnailPreviews.length(); i++) { @@ -350,7 +350,7 @@ public class ParsePost { int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY); int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY); - previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight)); + previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight, "", "")); } } } @@ -397,7 +397,7 @@ public class ParsePost { hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else if (url.endsWith("gif")){ @@ -490,7 +490,7 @@ public class ParsePost { spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (previews.isEmpty()) { - previews.add(new Post.Preview(url, 0, 0)); + previews.add(new Post.Preview(url, 0, 0, "", "")); } post.setPreviews(previews); } else if (url.endsWith("mp4")) { @@ -559,11 +559,24 @@ public class ParsePost { galleryItemUrl = sourceObject.getString(JSONUtils.MP4_KEY); } } + + JSONObject galleryItem = galleryIdsArray.getJSONObject(i); + String galleryItemCaption = ""; + String galleryItemCaptionUrl = ""; + if(galleryItem.has(JSONUtils.CAPTION_KEY)){ + galleryItemCaption = galleryItem.getString(JSONUtils.CAPTION_KEY).trim(); + } + + if(galleryItem.has(JSONUtils.CAPTION_URL_KEY)){ + galleryItemCaptionUrl = galleryItem.getString(JSONUtils.CAPTION_URL_KEY).trim(); + } + if ((previews.isEmpty()) && mimeType.contains("jpg") || mimeType.contains("png")) { previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY), - singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY))); + singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY), galleryItemCaption, galleryItemCaptionUrl)); } - gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1))); + + gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1), galleryItemCaption, galleryItemCaptionUrl)); } if (!gallery.isEmpty()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java index 6a0173c1..e19696a3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java @@ -582,8 +582,10 @@ public class Post implements Parcelable { public String url; public String fileName; public int mediaType; + public String caption; + public String captionUrl; - public Gallery(String mimeType, String url, String fileName) { + public Gallery(String mimeType, String url, String fileName, String caption, String captionUrl) { this.mimeType = mimeType; this.url = url; this.fileName = fileName; @@ -594,6 +596,8 @@ public class Post implements Parcelable { } else { mediaType = TYPE_VIDEO; } + this.caption = caption; + this.captionUrl = captionUrl; } protected Gallery(Parcel in) { @@ -601,6 +605,8 @@ public class Post implements Parcelable { url = in.readString(); fileName = in.readString(); mediaType = in.readInt(); + caption = in.readString(); + captionUrl = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -626,6 +632,8 @@ public class Post implements Parcelable { parcel.writeString(url); parcel.writeString(fileName); parcel.writeInt(mediaType); + parcel.writeString(caption); + parcel.writeString(captionUrl); } } @@ -633,17 +641,23 @@ public class Post implements Parcelable { private String previewUrl; private int previewWidth; private int previewHeight; + private String previewCaption; + private String previewCaptionUrl; - public Preview(String previewUrl, int previewWidth, int previewHeight) { + public Preview(String previewUrl, int previewWidth, int previewHeight, String previewCaption, String previewCaptionUrl) { this.previewUrl = previewUrl; this.previewWidth = previewWidth; this.previewHeight = previewHeight; + this.previewCaption = previewCaption; + this.previewCaptionUrl = previewCaptionUrl; } protected Preview(Parcel in) { previewUrl = in.readString(); previewWidth = in.readInt(); previewHeight = in.readInt(); + previewCaption = in.readString(); + previewCaptionUrl = in.readString(); } public static final Creator CREATOR = new Creator() { @@ -682,6 +696,18 @@ public class Post implements Parcelable { this.previewHeight = previewHeight; } + public String getPreviewCaption() { + return previewCaption; + } + + public void setPreviewCaption(String previewCaption) { this.previewCaption = previewCaption; } + + public String getPreviewCaptionUrl() { + return previewCaptionUrl; + } + + public void setPreviewCaptionUrl(String previewCaptionUrl) { this.previewCaptionUrl = previewCaptionUrl; } + @Override public int describeContents() { return 0; @@ -692,6 +718,8 @@ public class Post implements Parcelable { parcel.writeString(previewUrl); parcel.writeInt(previewWidth); parcel.writeInt(previewHeight); + parcel.writeString(previewCaption); + parcel.writeString(previewCaptionUrl); } } } 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 b76f198e..19ea43cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/JSONUtils.java @@ -171,4 +171,6 @@ public class JSONUtils { public static final String DISPLAY_STRING_KEY = "display_string"; public static final String RESULTS_KEY = "results"; public static final String CONTENT_MD_KEY = "content_md"; + public static final String CAPTION_KEY = "caption"; + public static final String CAPTION_URL_KEY = "outbound_url"; } -- cgit v1.2.3