Fix post content is not parsed in other types of posts.

This commit is contained in:
Docile-Alligator 2022-08-14 16:55:44 +10:00
parent 97dcc263e3
commit 633ccc7f7d
8 changed files with 131 additions and 96 deletions

View File

@ -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<Recycler
((PostDetailBaseViewHolder) holder).mSaveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailBaseViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
((PostDetailBaseViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter);
mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText());
mMarkwonAdapter.notifyDataSetChanged();
}
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
@ -752,7 +758,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
loadImage((PostDetailLinkViewHolder) holder, preview);
}
} else if (holder instanceof PostDetailNoPreviewViewHolder) {
if (mPost.getPostType() == Post.LINK_TYPE || mPost.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
if (!mHidePostType) {
@ -791,25 +796,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
break;
}
}
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailNoPreviewViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
}
@Override
public void onScrolledRight() {
((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
}
});
((PostDetailNoPreviewViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager);
((PostDetailNoPreviewViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter);
mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText());
mMarkwonAdapter.notifyDataSetChanged();
}
} else if (holder instanceof PostDetailGalleryViewHolder) {
Post.Preview preview = getSuitablePreview(mPost.getPreviews());
if (preview != null) {
@ -823,25 +809,6 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else {
((PostDetailGalleryViewHolder) holder).mNoPreviewPostTypeImageView.setVisibility(View.VISIBLE);
}
} else if (holder instanceof PostDetailTextViewHolder) {
if (mPost.getSelfText() != null && !mPost.getSelfText().equals("")) {
((PostDetailTextViewHolder) holder).mContentMarkdownView.setVisibility(View.VISIBLE);
LinearLayoutManagerBugFixed linearLayoutManager = new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
}
@Override
public void onScrolledRight() {
((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
}
});
((PostDetailTextViewHolder) holder).mContentMarkdownView.setLayoutManager(linearLayoutManager);
((PostDetailTextViewHolder) holder).mContentMarkdownView.setAdapter(mMarkwonAdapter);
mMarkwonAdapter.setMarkdown(mPostDetailMarkwon, mPost.getSelfText());
mMarkwonAdapter.notifyDataSetChanged();
}
}
}
}
@ -1075,6 +1042,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
((PostDetailBaseViewHolder) holder).mFlairTextView.setVisibility(View.GONE);
((PostDetailBaseViewHolder) holder).mSpoilerTextView.setVisibility(View.GONE);
((PostDetailBaseViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
((PostDetailBaseViewHolder) holder).mContentMarkdownView.setVisibility(View.GONE);
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
if (((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall != null && !((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrStreamableVideoCall.isCanceled()) {
@ -1137,6 +1105,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
CustomTextView mFlairTextView;
TextView mAwardsTextView;
TextView mUpvoteRatioTextView;
RecyclerView mContentMarkdownView;
ConstraintLayout mBottomConstraintLayout;
ImageView mUpvoteButton;
TextView mScoreTextView;
@ -1164,6 +1133,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
CustomTextView mFlairTextView,
TextView mAwardsTextView,
TextView mUpvoteRatioTextView,
RecyclerView mContentMarkdownView,
ConstraintLayout mBottomConstraintLayout,
ImageView mUpvoteButton,
TextView mScoreTextView,
@ -1186,6 +1156,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
this.mFlairTextView = mFlairTextView;
this.mAwardsTextView = mAwardsTextView;
this.mUpvoteRatioTextView = mUpvoteRatioTextView;
this.mContentMarkdownView = mContentMarkdownView;
this.mBottomConstraintLayout = mBottomConstraintLayout;
this.mUpvoteButton = mUpvoteButton;
this.mScoreTextView = mScoreTextView;
@ -1250,6 +1221,18 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mActivity.startActivity(intent);
});
mContentMarkdownView.setLayoutManager(new MarkwonLinearLayoutManager(mActivity, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() {
@Override
public void onScrolledLeft() {
((ViewPostDetailActivity) mActivity).lockSwipeRightToGoBack();
}
@Override
public void onScrolledRight() {
((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
}
}));
mUpvoteButton.setOnClickListener(view -> {
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<Recycler
ImageView muteButton;
@BindView(R.id.fullscreen_exo_playback_control_view)
ImageView fullscreenButton;
@BindView(R.id.content_markdown_view_item_post_detail_video_autoplay)
RecyclerView mContentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_detail_video_autoplay)
ConstraintLayout mBottomConstraintLayout;
@BindView(R.id.plus_button_item_post_detail_video_autoplay)
@ -1664,6 +1649,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -1873,6 +1859,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
ImageView videoOrGifIndicatorImageView;
@BindView(R.id.image_view_item_post_detail_video_and_gif_preview)
AspectRatioGifImageView mImageView;
@BindView(R.id.content_markdown_view_item_post_detail_video_and_gif_preview)
RecyclerView mContentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_detail_video_and_gif_preview)
ConstraintLayout mBottomConstraintLayout;
@BindView(R.id.plus_button_item_post_detail_video_and_gif_preview)
@ -1906,6 +1894,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -2000,6 +1989,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
TextView mLoadImageErrorTextView;
@BindView(R.id.image_view_item_post_detail_image_and_gif_autoplay)
AspectRatioGifImageView mImageView;
@BindView(R.id.content_markdown_view_item_post_detail_image_and_gif_autoplay)
RecyclerView mContentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_detail_image_and_gif_autoplay)
ConstraintLayout mBottomConstraintLayout;
@BindView(R.id.plus_button_item_post_detail_image_and_gif_autoplay)
@ -2033,6 +2024,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -2112,6 +2104,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
TextView mLoadImageErrorTextView;
@BindView(R.id.image_view_item_post_detail_link)
AspectRatioGifImageView mImageView;
@BindView(R.id.content_markdown_view_item_post_detail_link)
RecyclerView mContentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_detail_link)
ConstraintLayout mBottomConstraintLayout;
@BindView(R.id.plus_button_item_post_detail_link)
@ -2145,6 +2139,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -2240,6 +2235,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -2361,6 +2357,8 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
TextView mCaptionUrlTextView;
@BindView(R.id.image_view_no_preview_link_item_post_detail_gallery)
ImageView mNoPreviewPostTypeImageView;
@BindView(R.id.content_markdown_view_item_post_detail_gallery)
RecyclerView mContentMarkdownView;
@BindView(R.id.bottom_constraint_layout_item_post_detail_gallery)
ConstraintLayout mBottomConstraintLayout;
@BindView(R.id.plus_button_item_post_detail_gallery)
@ -2394,6 +2392,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,
@ -2493,6 +2492,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
mFlairTextView,
mAwardsTextView,
mUpvoteRatioTextView,
mContentMarkdownView,
mBottomConstraintLayout,
mUpvoteButton,
mScoreTextView,

View File

@ -267,35 +267,8 @@ public class ParsePost {
authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType,
voteType, nComments, upvoteRatio, flair, awards, nAwards, hidden, spoiler, nsfw,
stickied, archived, locked, saved, isCrosspost);
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 {
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;
}

View File

@ -320,6 +320,16 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottom_constraint_layout_item_post_detail_gallery"
android:layout_width="match_parent"

View File

@ -241,6 +241,16 @@
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_image_and_gif_autoplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -251,6 +251,16 @@
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_link"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -254,6 +254,16 @@
</RelativeLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_video_and_gif_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -235,6 +235,16 @@
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_video_autoplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -236,6 +236,16 @@
</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/content_markdown_view_item_post_detail_video_autoplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:visibility="gone"
android:nestedScrollingEnabled="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"