Show author flair (not richtext) for comments.

This commit is contained in:
Alex Ning 2020-04-16 20:04:32 +08:00
parent 9cbe542c85
commit f0125edd23
5 changed files with 23 additions and 19 deletions

View File

@ -826,17 +826,20 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String authorPrefixed = "u/" + comment.getAuthor(); String authorPrefixed = "u/" + comment.getAuthor();
((CommentViewHolder) holder).authorTextView.setText(authorPrefixed); ((CommentViewHolder) holder).authorTextView.setText(authorPrefixed);
if (comment.getAuthorFlair() != null && !comment.getAuthorFlair().equals("")) { if (comment.getAuthorFlairHTML() != null && !comment.getAuthorFlairHTML().equals("")) {
((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE); ((CommentViewHolder) holder).authorFlairTextView.setVisibility(View.VISIBLE);
Spannable flairHTML; Spannable flairHTML;
GlideImageGetter glideImageGetter = new GlideImageGetter(((CommentViewHolder) holder).authorFlairTextView); GlideImageGetter glideImageGetter = new GlideImageGetter(((CommentViewHolder) holder).authorFlairTextView);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { if (android.os.Build.VERSION.SDK_INT >= 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 { } 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.setText(flairHTML);
((CommentViewHolder) holder).authorFlairTextView.setOnClickListener(view -> ((CommentViewHolder) holder).authorTextView.performClick()); ((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()) { if (comment.isSubmitter()) {

View File

@ -26,6 +26,7 @@ public class CommentData implements Parcelable {
private String fullName; private String fullName;
private String author; private String author;
private String authorFlair; private String authorFlair;
private String authorFlairHTML;
private String linkAuthor; private String linkAuthor;
private String commentTime; private String commentTime;
private long commentTimeMillis; private long commentTimeMillis;
@ -52,15 +53,17 @@ public class CommentData implements Parcelable {
private boolean isLoadingMoreChildren; private boolean isLoadingMoreChildren;
private boolean loadMoreChildrenFailed; private boolean loadMoreChildrenFailed;
public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, public CommentData(String id, String fullName, String author, String authorFlair,
String commentTime, long commentTimeMillis, String commentMarkdown, String authorFlairHTML, String linkAuthor, String commentTime,
String commentRawText, String linkId, String subredditName, String parentId, long commentTimeMillis, String commentMarkdown, String commentRawText,
int score, int voteType, boolean isSubmitter, String distinguished, String permalink, String linkId, String subredditName, String parentId, int score, int voteType,
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { boolean isSubmitter, String distinguished, String permalink, int depth,
boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.author = author; this.author = author;
this.authorFlair = authorFlair; this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.linkAuthor = linkAuthor; this.linkAuthor = linkAuthor;
this.commentTime = commentTime; this.commentTime = commentTime;
this.commentTimeMillis = commentTimeMillis; this.commentTimeMillis = commentTimeMillis;
@ -97,6 +100,7 @@ public class CommentData implements Parcelable {
fullName = in.readString(); fullName = in.readString();
author = in.readString(); author = in.readString();
authorFlair = in.readString(); authorFlair = in.readString();
authorFlairHTML = in.readString();
linkAuthor = in.readString(); linkAuthor = in.readString();
commentTime = in.readString(); commentTime = in.readString();
commentTimeMillis = in.readLong(); commentTimeMillis = in.readLong();
@ -143,6 +147,10 @@ public class CommentData implements Parcelable {
return authorFlair; return authorFlair;
} }
public String getAuthorFlairHTML() {
return authorFlairHTML;
}
public String getLinkAuthor() { public String getLinkAuthor() {
return linkAuthor; return linkAuthor;
} }
@ -337,6 +345,7 @@ public class CommentData implements Parcelable {
parcel.writeString(fullName); parcel.writeString(fullName);
parcel.writeString(author); parcel.writeString(author);
parcel.writeString(authorFlair); parcel.writeString(authorFlair);
parcel.writeString(authorFlairHTML);
parcel.writeString(linkAuthor); parcel.writeString(linkAuthor);
parcel.writeString(commentTime); parcel.writeString(commentTime);
parcel.writeLong(commentTimeMillis); parcel.writeLong(commentTimeMillis);

View File

@ -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 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 linkId = singleCommentData.getString(JSONUtils.LINK_ID_KEY).substring(3);
String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY); String subredditName = singleCommentData.getString(JSONUtils.SUBREDDIT_KEY);
@ -168,7 +169,7 @@ public class ParseComment {
boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY); boolean collapsed = singleCommentData.getBoolean(JSONUtils.COLLAPSED_KEY);
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); 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, formattedSubmitTime, submitTime, commentMarkdown, commentRawText, linkId, subredditName,
parentId, score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, parentId, score, voteType, isSubmitter, distinguished, permalink, depth, collapsed,
hasReply, scoreHidden, saved); hasReply, scoreHidden, saved);

View File

@ -17,6 +17,7 @@ public class JSONUtils {
public static final String SELFTEXT_HTML_KEY = "selftext_html"; public static final String SELFTEXT_HTML_KEY = "selftext_html";
public static final String AUTHOR_KEY = "author"; public static final String AUTHOR_KEY = "author";
public static final String AUTHOR_FLAIR_RICHTEXT_KEY = "author_flair_richtext"; 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 E_KEY = "e";
public static final String T_KEY = "t"; public static final String T_KEY = "t";
public static final String U_KEY = "u"; public static final String U_KEY = "u";

View File

@ -161,16 +161,6 @@
app:lib_setRoundedView="true" app:lib_setRoundedView="true"
app:lib_setShape="rectangle" /> app:lib_setShape="rectangle" />
<TextView
android:id="@+id/gilded_number_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/gold"
android:textSize="?attr/font_default"
android:drawableStart="@drawable/gold"
android:drawablePadding="4dp"
android:visibility="gone" />
<ImageView <ImageView
android:id="@+id/archived_image_view_item_post_detail" android:id="@+id/archived_image_view_item_post_detail"
android:layout_width="20dp" android:layout_width="20dp"