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 ++++++++-------------- .../main/res/layout/item_post_detail_gallery.xml | 10 +++ .../item_post_detail_image_and_gif_autoplay.xml | 10 +++ app/src/main/res/layout/item_post_detail_link.xml | 10 +++ .../item_post_detail_video_and_gif_preview.xml | 10 +++ .../res/layout/item_post_detail_video_autoplay.xml | 10 +++ ...ost_detail_video_autoplay_legacy_controller.xml | 10 +++ 8 files changed, 131 insertions(+), 96 deletions(-) (limited to 'app/src/main') 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; } diff --git a/app/src/main/res/layout/item_post_detail_gallery.xml b/app/src/main/res/layout/item_post_detail_gallery.xml index a73e1965..dbdd849e 100644 --- a/app/src/main/res/layout/item_post_detail_gallery.xml +++ b/app/src/main/res/layout/item_post_detail_gallery.xml @@ -320,6 +320,16 @@ + + + + + + + + + + + +