From 633ccc7f7d72072dd83a5960d06d8dd58f9dbe00 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 14 Aug 2022 16:55:44 +1000 Subject: Fix post content is not parsed in other types of posts. --- .../adapters/PostDetailRecyclerViewAdapter.java | 80 ++++++++++---------- .../infinityforreddit/post/ParsePost.java | 87 ++++++++-------------- 2 files changed, 71 insertions(+), 96 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 bf6fabe9..88c2a723 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -108,7 +108,6 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.ShareLinkBottom import ml.docilealligator.infinityforreddit.bottomsheetfragments.UrlMenuBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.AspectRatioGifImageView; -import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.MarkwonLinearLayoutManager; import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment; import ml.docilealligator.infinityforreddit.markdown.SpoilerParserPlugin; @@ -657,6 +656,13 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter { if (mPost.isArchived()) { Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show(); @@ -1627,6 +1610,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter 250) { - selfTextPlain = selfTextPlain.substring(0, 250); - } - 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 { - if (url.endsWith("jpg") || url.endsWith("png")) { + if (url.endsWith("jpg") || url.endsWith("png") || url.endsWith("jpeg")) { //Image post int postType = Post.IMAGE_TYPE; @@ -496,34 +469,6 @@ public class ParsePost { //Need attention post.setPreviews(previews); - - if (data.isNull(JSONUtils.SELFTEXT_KEY)) { - post.setSelfText(""); - } else { - String selfText = Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()); - post.setSelfText(selfText); - if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { - post.setSelfTextPlainTrimmed(""); - } else { - String selfTextPlain = Utils.trimTrailingWhitespace( - Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString(); - post.setSelfTextPlain(selfTextPlain); - if (selfTextPlain.length() > 250) { - selfTextPlain = selfTextPlain.substring(0, 250); - } - 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 { //Link post int postType = Post.LINK_TYPE; @@ -747,6 +692,36 @@ public class ParsePost { } } + if (post.getPostType() != Post.LINK_TYPE && post.getPostType() != Post.NO_PREVIEW_LINK_TYPE) { + if (data.isNull(JSONUtils.SELFTEXT_KEY)) { + post.setSelfText(""); + } else { + String selfText = Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()); + post.setSelfText(selfText); + if (data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { + post.setSelfTextPlainTrimmed(""); + } else { + String selfTextPlain = Utils.trimTrailingWhitespace( + Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY))).toString(); + post.setSelfTextPlain(selfTextPlain); + if (selfTextPlain.length() > 250) { + selfTextPlain = selfTextPlain.substring(0, 250); + } + 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); + } + } + } + } + return post; } -- cgit v1.2.3