diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 14:54:12 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 14:54:12 +0000 |
commit | 75c9a52cf7c91c37bb3b350db1ce8b664822b250 (patch) | |
tree | 3b29b5476915c5f8ecb6f675e0b8dc790171e4bf /app/src/main | |
parent | 16014a8807dd22bb64d583d97ef6e315c9e56d5b (diff) | |
download | infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar.gz infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar.bz2 infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar.lz infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar.xz infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.tar.zst infinity-for-reddit-75c9a52cf7c91c37bb3b350db1ce8b664822b250.zip |
Hide post selftext if it contains spoiler in post feed.
Diffstat (limited to '')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java | 32 |
1 files changed, 28 insertions, 4 deletions
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 30118395..9df78a45 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java @@ -12,6 +12,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.readpost.ReadPost; @@ -176,7 +178,8 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { - post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); + String selfText = Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()); + post.setSelfText(selfText); if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfTextPlainTrimmed(""); } else { @@ -186,7 +189,17 @@ public class ParsePost { if (selfTextPlain.length() > 250) { selfTextPlain = selfTextPlain.substring(0, 250); } - post.setSelfTextPlainTrimmed(selfTextPlain); + if (!selfText.equals("")) { + Pattern p = Pattern.compile(">!.+!<"); + Matcher m = p.matcher(selfText.substring(0, Math.min(selfText.length(), 400))); + if (m.find()) { + post.setSelfTextPlainTrimmed(""); + } else { + post.setSelfTextPlainTrimmed(selfTextPlain); + } + } else { + post.setSelfTextPlainTrimmed(selfTextPlain); + } } } } else { @@ -320,7 +333,8 @@ public class ParsePost { if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { - post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim())); + String selfText = Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()); + post.setSelfText(selfText); if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfTextPlainTrimmed(""); } else { @@ -330,7 +344,17 @@ public class ParsePost { if (selfTextPlain.length() > 250) { selfTextPlain = selfTextPlain.substring(0, 250); } - post.setSelfTextPlainTrimmed(selfTextPlain); + if (!selfText.equals("")) { + Pattern p = Pattern.compile(">!.+!<"); + Matcher m = p.matcher(selfText.substring(0, Math.min(selfText.length(), 400))); + if (m.find()) { + post.setSelfTextPlainTrimmed(""); + } else { + post.setSelfTextPlainTrimmed(selfTextPlain); + } + } else { + post.setSelfTextPlainTrimmed(selfTextPlain); + } } } } else { |