aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-26 20:55:08 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2023-11-26 20:55:08 +0000
commite7b4b8aa8100327d83e99f2f0b3362a318e2c0eb (patch)
tree22925bca447c89c24546a1bc734570fb7b1d39c1 /app/src/main/java
parent4bcd60aafdfdc28c764c8239c82dab0886e40781 (diff)
downloadinfinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar.gz
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar.bz2
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar.lz
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar.xz
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.tar.zst
infinity-for-reddit-e7b4b8aa8100327d83e99f2f0b3362a318e2c0eb.zip
Show cations of preview images and gifs.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java22
5 files changed, 47 insertions, 22 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java
index 3a75e6c1..fd7d2a6a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MediaMetadata.java
@@ -12,6 +12,7 @@ public class MediaMetadata implements Parcelable {
//E.g. Image
public String e;
public String fileName;
+ public String caption;
public boolean isGIF;
public MediaItem original;
public MediaItem downscaled;
@@ -30,6 +31,7 @@ public class MediaMetadata implements Parcelable {
id = in.readString();
e = in.readString();
fileName = in.readString();
+ caption = in.readString();
isGIF = in.readByte() != 0;
original = in.readParcelable(MediaItem.class.getClassLoader());
downscaled = in.readParcelable(MediaItem.class.getClassLoader());
@@ -57,6 +59,7 @@ public class MediaMetadata implements Parcelable {
dest.writeString(id);
dest.writeString(e);
dest.writeString(fileName);
+ dest.writeString(caption);
dest.writeByte((byte) (isGIF ? 1 : 0));
dest.writeParcelable(original, flags);
dest.writeParcelable(downscaled, flags);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java
index 6b162fe6..8a80f1a4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java
@@ -270,7 +270,7 @@ public class ParseComment {
Map<String, MediaMetadata> mediaMetadataMap = JSONUtils.parseMediaMetadata(singleCommentData);
String commentMarkdown = "";
if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) {
- commentMarkdown = Utils.parseInlineRedditImages(
+ commentMarkdown = Utils.parseRedditImagesBlock(
Utils.modifyMarkdown(
Utils.trimTrailingWhitespace(singleCommentData.getString(JSONUtils.BODY_KEY))), mediaMetadataMap);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
index 86287cc0..9611a5dc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/ImageAndGifEntry.java
@@ -41,6 +41,8 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
private boolean dataSavingMode;
private boolean blurImage;
private int colorAccent;
+ private int primaryTextColor;
+ private int postContentColor;
public ImageAndGifEntry(BaseActivity baseActivity, RequestManager glide,
OnItemClickListener onItemClickListener) {
@@ -51,6 +53,8 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000")));
this.onItemClickListener = onItemClickListener;
colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent();
+ primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor();
+ postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor();
String dataSavingModeString = sharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF);
if (dataSavingModeString.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ALWAYS)) {
dataSavingMode = true;
@@ -63,13 +67,15 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
OnItemClickListener onItemClickListener) {
this.baseActivity = baseActivity;
this.glide = glide;
-
SharedPreferences sharedPreferences = baseActivity.getDefaultSharedPreferences();
this.saveMemoryCenterInsideDownsampleStrategy = new SaveMemoryCenterInisdeDownsampleStrategy(
Integer.parseInt(sharedPreferences.getString(SharedPreferencesUtils.POST_FEED_MAX_RESOLUTION, "5000000")));
this.onItemClickListener = onItemClickListener;
this.dataSavingMode = dataSavingMode;
this.blurImage = blurImage;
+ colorAccent = baseActivity.getCustomThemeWrapper().getColorAccent();
+ primaryTextColor = baseActivity.getCustomThemeWrapper().getPrimaryTextColor();
+ postContentColor = baseActivity.getCustomThemeWrapper().getPostContentColor();
}
@NonNull
@@ -120,6 +126,11 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
.downsample(saveMemoryCenterInsideDownsampleStrategy)
.into(holder.binding.imageViewMarkdownImageAndGifBlock);
}
+
+ if (node.mediaMetadata.caption != null) {
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setVisibility(View.VISIBLE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setText(node.mediaMetadata.caption);
+ }
}
@Override
@@ -137,6 +148,7 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
glide.clear(holder.binding.imageViewMarkdownImageAndGifBlock);
holder.binding.progressBarMarkdownImageAndGifBlock.setVisibility(View.GONE);
holder.binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setVisibility(View.GONE);
+ holder.binding.captionTextViewMarkdownImageAndGifBlock.setVisibility(View.GONE);
}
public class Holder extends MarkwonAdapter.Holder {
@@ -149,6 +161,15 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
this.binding = binding;
binding.progressBarMarkdownImageAndGifBlock.setIndeterminateTintList(ColorStateList.valueOf(colorAccent));
+ binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setTextColor(primaryTextColor);
+ binding.captionTextViewMarkdownImageAndGifBlock.setTextColor(postContentColor);
+
+ if (baseActivity.typeface != null) {
+ binding.loadImageErrorTextViewMarkdownImageAndGifBlock.setTypeface(baseActivity.typeface);
+ }
+ if (baseActivity.contentTypeface != null) {
+ binding.captionTextViewMarkdownImageAndGifBlock.setTypeface(baseActivity.contentTypeface);
+ }
requestListener = new RequestListener<>() {
@Override
@@ -172,17 +193,6 @@ public class ImageAndGifEntry extends MarkwonAdapter.Entry<ImageAndGifBlock, Ima
});
}
- /*public Holder(@NonNull AdapterGifEntryBinding binding) {
- super(binding.getRoot());
- this.binding = binding;
-
- binding.progressBar.setIndeterminateTintList(ColorStateList.valueOf(customThemeWrapper.getColorAccent()));
- binding.giphyWatermark.setTextColor(customThemeWrapper.getCommentColor());
-
- binding.gifLink.setTextColor(customThemeWrapper.getLinkColor());
-
- }*/
-
/*void bindImage(ImageMetadata image) {
binding.gifLink.setVisibility(View.GONE);
binding.iv.setVisibility(View.VISIBLE);
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 ddbde65c..f7a4a03e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -306,7 +306,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
} else {
- post.setSelfText(Utils.parseInlineRedditImages(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
+ post.setSelfText(Utils.parseRedditImagesBlock(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
}
String authority = uri.getAuthority();
@@ -492,7 +492,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
} else {
- post.setSelfText(Utils.parseInlineRedditImages(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
+ post.setSelfText(Utils.parseRedditImagesBlock(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
}
post.setPreviews(previews);
@@ -567,7 +567,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
} else {
- post.setSelfText(Utils.parseInlineRedditImages(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
+ post.setSelfText(Utils.parseRedditImagesBlock(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap));
}
String authority = uri.getAuthority();
@@ -711,7 +711,7 @@ public class ParsePost {
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
} else {
- String selfText = Utils.parseInlineRedditImages(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap);
+ String selfText = Utils.parseRedditImagesBlock(Utils.modifyMarkdown(Utils.trimTrailingWhitespace(data.getString(JSONUtils.SELFTEXT_KEY))), mediaMetadataMap);
post.setSelfText(selfText);
if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
post.setSelfTextPlainTrimmed("");
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 9f3167b9..e945fa71 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -87,7 +87,7 @@ public final class Utils {
return regexed;
}
- public static String parseInlineRedditImages(String markdown, @Nullable Map<String, MediaMetadata> mediaMetadataMap) {
+ public static String parseRedditImagesBlock(String markdown, @Nullable Map<String, MediaMetadata> mediaMetadataMap) {
if (mediaMetadataMap == null) {
return markdown;
}
@@ -99,27 +99,33 @@ public final class Utils {
int previewReddItLength = "https://preview.redd.it/".length();
while (matcher.find(start)) {
String id;
+ String caption = null;
if (markdownStringBuilder.charAt(matcher.start()) == '[') {
//Has caption
int urlStartIndex = markdownStringBuilder.lastIndexOf("https://preview.redd.it/", matcher.end());
id = markdownStringBuilder.substring(previewReddItLength + urlStartIndex,
markdownStringBuilder.indexOf(".", previewReddItLength + urlStartIndex));
+ //Minus "](".length()
+ caption = markdownStringBuilder.substring(matcher.start() + 1, urlStartIndex - 2);
} else {
id = markdownStringBuilder.substring(matcher.start() + previewReddItLength,
markdownStringBuilder.indexOf(".", matcher.start() + previewReddItLength));
}
- if (!mediaMetadataMap.containsKey(id)) {
+ MediaMetadata mediaMetadata = mediaMetadataMap.get(id);
+ if (mediaMetadata == null) {
start = matcher.end();
continue;
}
+ mediaMetadata.caption = caption;
+
if (markdownStringBuilder.charAt(matcher.start()) == '[') {
//Has caption
markdownStringBuilder.insert(matcher.start(), '!');
start = matcher.end() + 1;
} else {
- String replacingText = "![img](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")";
+ String replacingText = "![](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")";
markdownStringBuilder.replace(matcher.start(), matcher.end(), replacingText);
start = replacingText.length() + matcher.start();
}
@@ -133,26 +139,32 @@ public final class Utils {
int iReddItLength = "https://i.redd.it/".length();
while (matcher.find(start)) {
String id;
+ String caption = null;
if (markdownStringBuilder.charAt(matcher.start()) == '[') {
//Has caption
int urlStartIndex = markdownStringBuilder.lastIndexOf("https://i.redd.it/", matcher.end());
id = markdownStringBuilder.substring(iReddItLength + urlStartIndex,
markdownStringBuilder.indexOf(".", iReddItLength + urlStartIndex));
+ //Minus "](".length()
+ caption = markdownStringBuilder.substring(matcher.start() + 1, urlStartIndex - 2);
} else {
id = markdownStringBuilder.substring(matcher.start() + iReddItLength, matcher.start() + markdownStringBuilder.indexOf(".", iReddItLength));
}
- if (!mediaMetadataMap.containsKey(id)) {
+ MediaMetadata mediaMetadata = mediaMetadataMap.get(id);
+ if (mediaMetadata == null) {
start = matcher.end();
continue;
}
+ mediaMetadata.caption = caption;
+
if (markdownStringBuilder.charAt(matcher.start()) == '[') {
//Has caption
markdownStringBuilder.insert(matcher.start(), '!');
start = matcher.end() + 1;
} else {
- String replacingText = "![img](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")";
+ String replacingText = "![](" + markdownStringBuilder.substring(matcher.start(), matcher.end()) + ")";
markdownStringBuilder.replace(matcher.start(), matcher.end(), replacingText);
start = replacingText.length() + matcher.start();
}