aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
-rw-r--r--app/src/main/res/layout/markdown_image_and_gif_block.xml55
6 files changed, 84 insertions, 40 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();
}
diff --git a/app/src/main/res/layout/markdown_image_and_gif_block.xml b/app/src/main/res/layout/markdown_image_and_gif_block.xml
index 264a80e8..8e0aad32 100644
--- a/app/src/main/res/layout/markdown_image_and_gif_block.xml
+++ b/app/src/main/res/layout/markdown_image_and_gif_block.xml
@@ -1,33 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/image_wrapper_relative_layout_markdown_image_and_gif_block"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:orientation="vertical"
android:padding="8dp">
- <ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView
- android:id="@+id/image_view_markdown_image_and_gif_block"
+ <FrameLayout
+ android:id="@+id/image_wrapper_relative_layout_markdown_image_and_gif_block"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:adjustViewBounds="true" />
+ android:layout_height="wrap_content">
- <ProgressBar
- android:id="@+id/progress_bar_markdown_image_and_gif_block"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center" />
+ <ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView
+ android:id="@+id/image_view_markdown_image_and_gif_block"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:adjustViewBounds="true" />
+
+ <ProgressBar
+ android:id="@+id/progress_bar_markdown_image_and_gif_block"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center" />
+
+ <TextView
+ android:id="@+id/load_image_error_text_view_markdown_image_and_gif_block"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:fontFamily="?attr/font_family"
+ android:gravity="center"
+ android:text="@string/error_loading_image_tap_to_retry"
+ android:textSize="?attr/font_default"
+ android:visibility="gone"
+ app:drawableTopCompat="@drawable/ic_error_outline_black_24dp" />
+
+ </FrameLayout>
<TextView
- android:id="@+id/load_image_error_text_view_markdown_image_and_gif_block"
- android:layout_width="match_parent"
+ android:id="@+id/caption_text_view_markdown_image_and_gif_block"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center"
+ android:layout_marginTop="4dp"
+ android:layout_gravity="center_horizontal"
android:fontFamily="?attr/font_family"
android:gravity="center"
- android:text="@string/error_loading_image_tap_to_retry"
android:textSize="?attr/font_default"
- android:visibility="gone"
- app:drawableTopCompat="@drawable/ic_error_outline_black_24dp" />
+ android:visibility="gone" />
-</FrameLayout> \ No newline at end of file
+</LinearLayout>