diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-06 15:43:32 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-06 15:43:32 +0000 |
commit | bedcf6d0b626a447d4fec40e3e33b4fe0339ea38 (patch) | |
tree | fd52b034f3f4bdabbc257a4186982680289c9e17 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 98a66a8bb780e083dd82a34bdff240ce132a755c (diff) | |
download | infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar.gz infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar.bz2 infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar.lz infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar.xz infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.tar.zst infinity-for-reddit-bedcf6d0b626a447d4fec40e3e33b4fe0339ea38.zip |
Support inline gif in comments.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java | 2 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java | 19 |
2 files changed, 20 insertions, 1 deletions
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 0b38c530..d5a41dd1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/ParseComment.java @@ -140,7 +140,7 @@ public class ParseComment { String distinguished = singleCommentData.getString(JSONUtils.DISTINGUISHED_KEY); String commentMarkdown = ""; if (!singleCommentData.isNull(JSONUtils.BODY_KEY)) { - commentMarkdown = Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim()); + commentMarkdown = Utils.parseInlineGifInComments(Utils.modifyMarkdown(singleCommentData.getString(JSONUtils.BODY_KEY).trim())); } String commentRawText = Utils.trimTrailingWhitespace( Html.fromHtml(singleCommentData.getString(JSONUtils.BODY_HTML_KEY))).toString(); 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 f7a7d247..4cea425b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java @@ -22,6 +22,8 @@ import androidx.core.text.HtmlCompat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SortType; @@ -93,6 +95,23 @@ public class Utils { return regexed.toString(); } + public static String parseInlineGifInComments(String markdown) { + StringBuilder markdownStringBuilder = new StringBuilder(markdown); + Pattern inlineGifPattern = Pattern.compile("!\\[gif]\\(giphy\\|\\w+\\)"); + Matcher matcher = inlineGifPattern.matcher(markdownStringBuilder); + while (matcher.find()) { + markdownStringBuilder.replace(matcher.start(), matcher.end(), "[gif](https://media3.giphy.com/media/" + markdownStringBuilder.substring(matcher.start() + "![gif](giphy|".length(), matcher.end() - 1) + "/giphy.mp4)"); + } + + Pattern inlineGifPattern2 = Pattern.compile("!\\[gif]\\(giphy\\|\\w+\\|downsized\\)"); + Matcher matcher2 = inlineGifPattern2.matcher(markdownStringBuilder); + while (matcher2.find()) { + markdownStringBuilder.replace(matcher2.start(), matcher2.end(), "[gif](https://media3.giphy.com/media/" + markdownStringBuilder.substring(matcher2.start() + "![gif](giphy|".length(), matcher2.end() - "|downsized\\)".length()) + "/giphy.mp4)"); + } + + return markdownStringBuilder.toString(); + } + public static CharSequence trimTrailingWhitespace(CharSequence source) { if(source == null) |