Fix comment rendering

There were some issues rendering markdown in comments. Now its fixed.
This commit is contained in:
Bazsalanszky 2024-08-12 13:16:18 +02:00
parent 767e75b798
commit 0c8e3e3ea5
3 changed files with 14 additions and 84 deletions

View File

@ -203,10 +203,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
} else { } else {
((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern)); ((CommentBaseViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
} }
mMarkwon.setMarkdown(((CommentBaseViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
((CommentViewHolder) holder).markwonAdapter.setMarkdown(mMarkwon, comment.getCommentMarkdown());
// noinspection NotifyDataSetChanged
((CommentBaseViewHolder) holder).markwonAdapter.notifyDataSetChanged();
String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes, String commentText = Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()); comment.getScore() + comment.getVoteType());
@ -254,8 +251,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (holder instanceof CommentBaseViewHolder) { if (holder instanceof CommentBaseViewHolder) {
((CommentBaseViewHolder) holder).authorFlairTextView.setText(""); ((CommentBaseViewHolder) holder).authorFlairTextView.setText("");
((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE); ((CommentBaseViewHolder) holder).authorFlairTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); ((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor)); ((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor); ((CommentBaseViewHolder) holder).scoreTextView.setTextColor(mCommentIconAndInfoColor);
@ -327,8 +322,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
TextView authorTextView; TextView authorTextView;
TextView authorFlairTextView; TextView authorFlairTextView;
TextView commentTimeTextView; TextView commentTimeTextView;
TextView awardsTextView; TextView commentMarkdownView;
RecyclerView commentMarkdownView;
ConstraintLayout bottomConstraintLayout; ConstraintLayout bottomConstraintLayout;
MaterialButton upvoteButton; MaterialButton upvoteButton;
TextView scoreTextView; TextView scoreTextView;
@ -338,7 +332,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
MaterialButton saveButton; MaterialButton saveButton;
MaterialButton replyButton; MaterialButton replyButton;
View commentDivider; View commentDivider;
CustomMarkwonAdapter markwonAdapter;
CommentBaseViewHolder(@NonNull View itemView) { CommentBaseViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -348,8 +341,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
TextView authorTextView, TextView authorTextView,
TextView authorFlairTextView, TextView authorFlairTextView,
TextView commentTimeTextView, TextView commentTimeTextView,
TextView awardsTextView, TextView commentMarkdownView,
RecyclerView commentMarkdownView,
ConstraintLayout bottomConstraintLayout, ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton, MaterialButton upvoteButton,
TextView scoreTextView, TextView scoreTextView,
@ -365,7 +357,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
this.authorTextView = authorTextView; this.authorTextView = authorTextView;
this.authorFlairTextView = authorFlairTextView; this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView; this.commentTimeTextView = commentTimeTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView; this.commentMarkdownView = commentMarkdownView;
this.bottomConstraintLayout = bottomConstraintLayout; this.bottomConstraintLayout = bottomConstraintLayout;
this.upvoteButton = upvoteButton; this.upvoteButton = upvoteButton;
@ -430,14 +421,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
authorTextView.setTypeface(mActivity.typeface); authorTextView.setTypeface(mActivity.typeface);
authorFlairTextView.setTypeface(mActivity.typeface); authorFlairTextView.setTypeface(mActivity.typeface);
commentTimeTextView.setTypeface(mActivity.typeface); commentTimeTextView.setTypeface(mActivity.typeface);
awardsTextView.setTypeface(mActivity.typeface);
upvoteButton.setTypeface(mActivity.typeface); upvoteButton.setTypeface(mActivity.typeface);
} }
itemView.setBackgroundColor(mCommentBackgroundColor); itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor); authorTextView.setTextColor(mUsernameColor);
authorFlairTextView.setTextColor(mAuthorFlairColor); authorFlairTextView.setTextColor(mAuthorFlairColor);
commentTimeTextView.setTextColor(mSecondaryTextColor); commentTimeTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor)); upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor)); downvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
@ -495,7 +484,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
} }
}); });
commentMarkdownView.setRecycledViewPool(recycledViewPool);
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() { LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() {
@Override @Override
public void lockSwipe() { public void lockSwipe() {
@ -507,18 +496,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mActivity.unlockSwipeRightToGoBack(); mActivity.unlockSwipeRightToGoBack();
} }
}); });
commentMarkdownView.setLayoutManager(linearLayoutManager);
markwonAdapter = MarkdownUtils.createCustomTablesAdapter();
markwonAdapter.setOnClickListener(view -> {
if (view instanceof SpoilerOnClickTextView) {
if (((SpoilerOnClickTextView) view).isSpoilerOnClick()) {
((SpoilerOnClickTextView) view).setSpoilerOnClick(false);
return;
}
}
itemView.callOnClick();
});
commentMarkdownView.setAdapter(markwonAdapter);
upvoteButton.setOnClickListener(view -> { upvoteButton.setOnClickListener(view -> {
if (mAccessToken == null) { if (mAccessToken == null) {
@ -739,7 +717,6 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
binding.authorTextViewItemPostComment, binding.authorTextViewItemPostComment,
binding.authorFlairTextViewItemPostComment, binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment, binding.commentTimeTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment, binding.commentMarkdownViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment, binding.bottomConstraintLayoutItemPostComment,
binding.upvoteButtonItemPostComment, binding.upvoteButtonItemPostComment,

View File

@ -465,10 +465,8 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
text = "*"+mActivity.getString(R.string.deleted_by_creator)+"*"; text = "*"+mActivity.getString(R.string.deleted_by_creator)+"*";
} }
mCommentMarkwon.setMarkdown(((CommentBaseViewHolder) holder).commentMarkdownView,text);
((CommentBaseViewHolder) holder).mMarkwonAdapter.setMarkdown(mCommentMarkwon,text);
// noinspection NotifyDataSetChanged
((CommentBaseViewHolder) holder).mMarkwonAdapter.notifyDataSetChanged();
if (mHideDownvotes) { if (mHideDownvotes) {
((CommentBaseViewHolder) holder).downvoteButton.setVisibility(View.GONE); ((CommentBaseViewHolder) holder).downvoteButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.GONE); ((CommentBaseViewHolder) holder).downvoteTextView.setVisibility(View.GONE);
@ -1180,8 +1178,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); ((CommentBaseViewHolder) holder).authorTextView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
mGlide.clear(((CommentBaseViewHolder) holder).authorIconImageView); mGlide.clear(((CommentBaseViewHolder) holder).authorIconImageView);
((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor); ((CommentBaseViewHolder) holder).topScoreTextView.setTextColor(mSecondaryTextColor);
((CommentBaseViewHolder) holder).awardsTextView.setText("");
((CommentBaseViewHolder) holder).awardsTextView.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).expandButton.setVisibility(View.GONE); ((CommentBaseViewHolder) holder).expandButton.setVisibility(View.GONE);
((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp); ((CommentBaseViewHolder) holder).upvoteButton.setIconResource(R.drawable.ic_upvote_24dp);
((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor)); ((CommentBaseViewHolder) holder).upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
@ -1231,8 +1227,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
TextView authorFlairTextView; TextView authorFlairTextView;
TextView commentTimeTextView; TextView commentTimeTextView;
TextView topScoreTextView; TextView topScoreTextView;
TextView awardsTextView; TextView commentMarkdownView;
RecyclerView commentMarkdownView;
TextView editedTextView; TextView editedTextView;
ConstraintLayout bottomConstraintLayout; ConstraintLayout bottomConstraintLayout;
MaterialButton upvoteButton; MaterialButton upvoteButton;
@ -1246,7 +1241,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
MaterialButton replyButton; MaterialButton replyButton;
CommentIndentationView commentIndentationView; CommentIndentationView commentIndentationView;
View commentDivider; View commentDivider;
CustomMarkwonAdapter mMarkwonAdapter;
CommentBaseViewHolder(@NonNull View itemView) { CommentBaseViewHolder(@NonNull View itemView) {
super(itemView); super(itemView);
@ -1258,8 +1252,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
TextView authorFlairTextView, TextView authorFlairTextView,
TextView commentTimeTextView, TextView commentTimeTextView,
TextView topScoreTextView, TextView topScoreTextView,
TextView awardsTextView, TextView commentMarkdownView,
RecyclerView commentMarkdownView,
TextView editedTextView, TextView editedTextView,
ConstraintLayout bottomConstraintLayout, ConstraintLayout bottomConstraintLayout,
MaterialButton upvoteButton, MaterialButton upvoteButton,
@ -1279,7 +1272,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
this.authorFlairTextView = authorFlairTextView; this.authorFlairTextView = authorFlairTextView;
this.commentTimeTextView = commentTimeTextView; this.commentTimeTextView = commentTimeTextView;
this.topScoreTextView = topScoreTextView; this.topScoreTextView = topScoreTextView;
this.awardsTextView = awardsTextView;
this.commentMarkdownView = commentMarkdownView; this.commentMarkdownView = commentMarkdownView;
this.editedTextView = editedTextView; this.editedTextView = editedTextView;
this.bottomConstraintLayout = bottomConstraintLayout; this.bottomConstraintLayout = bottomConstraintLayout;
@ -1357,7 +1349,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
authorFlairTextView.setTypeface(mActivity.typeface); authorFlairTextView.setTypeface(mActivity.typeface);
topScoreTextView.setTypeface(mActivity.typeface); topScoreTextView.setTypeface(mActivity.typeface);
editedTextView.setTypeface(mActivity.typeface); editedTextView.setTypeface(mActivity.typeface);
awardsTextView.setTypeface(mActivity.typeface);
scoreTextView.setTypeface(mActivity.typeface); scoreTextView.setTypeface(mActivity.typeface);
downvoteTextView.setTypeface(mActivity.typeface); downvoteTextView.setTypeface(mActivity.typeface);
expandButton.setTypeface(mActivity.typeface); expandButton.setTypeface(mActivity.typeface);
@ -1370,7 +1362,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((ConstraintLayout.LayoutParams) authorFlairTextView.getLayoutParams()).leftMargin = 0; ((ConstraintLayout.LayoutParams) authorFlairTextView.getLayoutParams()).leftMargin = 0;
} }
commentMarkdownView.setRecycledViewPool(recycledViewPool);
LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() { LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(mActivity, new SwipeLockInterface() {
@Override @Override
public void lockSwipe() { public void lockSwipe() {
@ -1382,9 +1374,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack(); ((ViewPostDetailActivity) mActivity).unlockSwipeRightToGoBack();
} }
}); });
commentMarkdownView.setLayoutManager(linearLayoutManager);
mMarkwonAdapter = MarkdownUtils.createCustomTablesAdapter();
commentMarkdownView.setAdapter(mMarkwonAdapter);
itemView.setBackgroundColor(mCommentBackgroundColor); itemView.setBackgroundColor(mCommentBackgroundColor);
authorTextView.setTextColor(mUsernameColor); authorTextView.setTextColor(mUsernameColor);
@ -1393,7 +1382,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
topScoreTextView.setTextColor(mSecondaryTextColor); topScoreTextView.setTextColor(mSecondaryTextColor);
downvoteTextView.setTextColor(mSecondaryTextColor); downvoteTextView.setTextColor(mSecondaryTextColor);
editedTextView.setTextColor(mSecondaryTextColor); editedTextView.setTextColor(mSecondaryTextColor);
awardsTextView.setTextColor(mSecondaryTextColor);
commentDivider.setBackgroundColor(mDividerColor); commentDivider.setBackgroundColor(mDividerColor);
upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor)); upvoteButton.setIconTint(ColorStateList.valueOf(mCommentIconAndInfoColor));
scoreTextView.setTextColor(mCommentIconAndInfoColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
@ -1814,41 +1802,19 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar(); View.OnLongClickListener hideToolbarOnLongClickListener = view -> hideToolbar();
itemView.setOnLongClickListener(hideToolbarOnLongClickListener); itemView.setOnLongClickListener(hideToolbarOnLongClickListener);
commentTimeTextView.setOnLongClickListener(hideToolbarOnLongClickListener); commentTimeTextView.setOnLongClickListener(hideToolbarOnLongClickListener);
mMarkwonAdapter.setOnLongClickListener(v -> { commentMarkdownView.setOnLongClickListener(v -> {
if (v instanceof TextView) { hideToolbar();
if (((TextView) v).getSelectionStart() == -1 && ((TextView) v).getSelectionEnd() == -1) {
hideToolbar();
}
}
return true; return true;
}); });
} }
mMarkwonAdapter.setOnClickListener(v -> {
if (v instanceof SpoilerOnClickTextView) {
if (((SpoilerOnClickTextView) v).isSpoilerOnClick()) {
((SpoilerOnClickTextView) v).setSpoilerOnClick(false);
return;
}
}
expandComments();
});
itemView.setOnClickListener(view -> expandComments()); itemView.setOnClickListener(view -> expandComments());
} else { } else {
if (mCommentToolbarHideOnClick) { if (mCommentToolbarHideOnClick) {
mMarkwonAdapter.setOnClickListener(view -> {
if (view instanceof SpoilerOnClickTextView) {
if (((SpoilerOnClickTextView) view).isSpoilerOnClick()) {
((SpoilerOnClickTextView) view).setSpoilerOnClick(false);
return;
}
}
hideToolbar();
});
View.OnClickListener hideToolbarOnClickListener = view -> hideToolbar(); View.OnClickListener hideToolbarOnClickListener = view -> hideToolbar();
itemView.setOnClickListener(hideToolbarOnClickListener); itemView.setOnClickListener(hideToolbarOnClickListener);
commentTimeTextView.setOnClickListener(hideToolbarOnClickListener); commentTimeTextView.setOnClickListener(hideToolbarOnClickListener);
} }
mMarkwonAdapter.setOnLongClickListener(view -> { commentMarkdownView.setOnLongClickListener(view -> {
if (view instanceof TextView) { if (view instanceof TextView) {
if (((TextView) view).getSelectionStart() == -1 && ((TextView) view).getSelectionEnd() == -1) { if (((TextView) view).getSelectionStart() == -1 && ((TextView) view).getSelectionEnd() == -1) {
expandComments(); expandComments();
@ -1896,7 +1862,6 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi
binding.authorFlairTextViewItemPostComment, binding.authorFlairTextViewItemPostComment,
binding.commentTimeTextViewItemPostComment, binding.commentTimeTextViewItemPostComment,
binding.topScoreTextViewItemPostComment, binding.topScoreTextViewItemPostComment,
binding.awardsTextViewItemComment,
binding.commentMarkdownViewItemPostComment, binding.commentMarkdownViewItemPostComment,
binding.editedTextViewItemPostComment, binding.editedTextViewItemPostComment,
binding.bottomConstraintLayoutItemPostComment, binding.bottomConstraintLayoutItemPostComment,

View File

@ -125,23 +125,11 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<TextView <TextView
android:id="@+id/awards_text_view_item_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:visibility="gone"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
tools:visibility="visible" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/comment_markdown_view_item_post_comment" android:id="@+id/comment_markdown_view_item_post_comment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginStart="8dp" android:layout_marginStart="16dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:nestedScrollingEnabled="false" /> android:nestedScrollingEnabled="false" />