From f0125edd233bb433c2d59cc04144be1e4a65bd0e Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 16 Apr 2020 20:04:32 +0800 Subject: Show author flair (not richtext) for comments. --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 9 ++++++--- .../infinityforreddit/CommentData.java | 19 ++++++++++++++----- .../infinityforreddit/ParseComment.java | 3 ++- .../infinityforreddit/Utils/JSONUtils.java | 1 + 4 files changed, 23 insertions(+), 9 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index 4338209e..49bc1f3e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -826,17 +826,20 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.N) { - flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlair(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); + flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlairHTML(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); } else { - flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlair(), glideImageGetter, null); + flairHTML = (Spannable) Html.fromHtml(comment.getAuthorFlairHTML(), glideImageGetter, null); } ((CommentViewHolder) holder).authorFlairTextView.setText(flairHTML); ((CommentViewHolder) holder).authorFlairTextView.setOnClickListener(view -> ((CommentViewHolder) holder).authorTextView.performClick()); + } else if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) { + ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE); + ((CommentViewHolder) holder).authorFlairTextView.setText(comment.getAuthorFlair()); } if (comment.isSubmitter()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java index 2396aa9b..0b37ed83 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java @@ -26,6 +26,7 @@ public class CommentData implements Parcelable { private String fullName; private String author; private String authorFlair; + private String authorFlairHTML; private String linkAuthor; private String commentTime; private long commentTimeMillis; @@ -52,15 +53,17 @@ public class CommentData implements Parcelable { private boolean isLoadingMoreChildren; private boolean loadMoreChildrenFailed; - public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, - String commentTime, long commentTimeMillis, String commentMarkdown, - String commentRawText, String linkId, String subredditName, String parentId, - int score, int voteType, boolean isSubmitter, String distinguished, String permalink, - int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { + public CommentData(String id, String fullName, String author, String authorFlair, + String authorFlairHTML, String linkAuthor, String commentTime, + long commentTimeMillis, String commentMarkdown, String commentRawText, + String linkId, String subredditName, String parentId, int score, int voteType, + boolean isSubmitter, String distinguished, String permalink, int depth, + boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { this.id = id; this.fullName = fullName; this.author = author; this.authorFlair = authorFlair; + this.authorFlairHTML = authorFlairHTML; this.linkAuthor = linkAuthor; this.commentTime = commentTime; this.commentTimeMillis = commentTimeMillis; @@ -97,6 +100,7 @@ public class CommentData implements Parcelable { fullName = in.readString(); author = in.readString(); authorFlair = in.readString(); + authorFlairHTML = in.readString(); linkAuthor = in.readString(); commentTime = in.readString(); commentTimeMillis = in.readLong(); @@ -143,6 +147,10 @@ public class CommentData implements Parcelable { return authorFlair; } + public String getAuthorFlairHTML() { + return authorFlairHTML; + } + public String getLinkAuthor() { return linkAuthor; } @@ -337,6 +345,7 @@ public class CommentData implements Parcelable { parcel.writeString(fullName); parcel.writeString(author); parcel.writeString(authorFlair); + parcel.writeString(authorFlairHTML); parcel.writeString(linkAuthor); parcel.writeString(commentTime); parcel.writeLong(commentTimeMillis); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java index 0891e7f1..fc5b829c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java @@ -131,6 +131,7 @@ public class ParseComment { } } } + String authorFlair = singleCommentData.isNull(JSONUtils.AUTHOR_FLAIR_TEXT_KEY) ? "" : singleCommentData.getString(JSONUtils.AUTHOR_FLAIR_TEXT_KEY); String linkAuthor = singleCommentData.has(JSONUtils.LINK_AUTHOR_KEY) ? singleCommentData.getString(JSONUtils.LINK_AUTHOR_KEY) : null; String linkId = singleCommentData.getString(JSONUtils.LINK_ID_KEY).substring(3); String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY); @@ -168,7 +169,7 @@ public class ParseComment { boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY); boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); - return new CommentData(id, fullName, author, authorFlairHTMLBuilder.toString(), linkAuthor, + return new CommentData(id, fullName, author, authorFlair, authorFlairHTMLBuilder.toString(), linkAuthor, formattedSubmitTime, submitTime, commentMarkdown, commentRawText, linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index 603717d4..ab3081b9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -17,6 +17,7 @@ public class JSONUtils { public static final String SELFTEXT_HTML_KEY = "selftext_html"; public static final String AUTHOR_KEY = "author"; public static final String AUTHOR_FLAIR_RICHTEXT_KEY = "author_flair_richtext"; + public static final String AUTHOR_FLAIR_TEXT_KEY = "author_flair_text"; public static final String E_KEY = "e"; public static final String T_KEY = "t"; public static final String U_KEY = "u"; -- cgit v1.2.3