From 504b005cf7b9d9881b6780ede5f75b7bcf2c6cd2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 16 Apr 2020 21:50:25 +0800 Subject: Show awards for comments. --- .../Adapter/CommentAndPostRecyclerViewAdapter.java | 17 ++++ .../infinityforreddit/CommentData.java | 15 ++- .../infinityforreddit/ParseComment.java | 22 ++++- .../infinityforreddit/ParsePost.java | 108 +++++++++++++-------- .../infinityforreddit/Post/Post.java | 49 +++++++--- 5 files changed, 150 insertions(+), 61 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 49bc1f3e..250d17d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -871,6 +871,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= android.os.Build.VERSION_CODES.N) { + awardsHTML = (Spannable) Html.fromHtml(comment.getAwards(), Html.FROM_HTML_MODE_LEGACY, glideImageGetter, null); + } else { + awardsHTML = (Spannable) Html.fromHtml(comment.getAwards(), glideImageGetter, null); + } + ((CommentViewHolder) holder).awardsTextView.setText(awardsHTML); + } + mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, comment.getScore() + comment.getVoteType())); @@ -1749,6 +1761,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter 4) { + String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY); + awardingsBuilder.append(" ").append("x").append(count).append(" "); + } else if (icons.length() > 0) { + String iconUrl = icons.getJSONObject(icons.length() - 1).getString(JSONUtils.URL_KEY); + awardingsBuilder.append(" ").append("x").append(count).append(" "); + } + } int score = singleCommentData.getInt(JSONUtils.SCORE_KEY); int voteType; if (singleCommentData.isNull(JSONUtils.LIKES_KEY)) { @@ -169,10 +183,10 @@ 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, authorFlair, authorFlairHTMLBuilder.toString(), linkAuthor, - formattedSubmitTime, submitTime, commentMarkdown, commentRawText, linkId, subredditName, - parentId, score, voteType, isSubmitter, distinguished, permalink, depth, collapsed, - hasReply, scoreHidden, saved); + return new CommentData(id, fullName, author, authorFlair, authorFlairHTMLBuilder.toString(), + linkAuthor, formattedSubmitTime, submitTime, commentMarkdown, commentRawText, + linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished, + permalink, awardingsBuilder.toString(),depth, collapsed, hasReply, scoreHidden, saved); } @Nullable diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index 3874de35..49329844 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -37,6 +37,20 @@ public class ParsePost { String subredditName = data.getString(JSONUtils.SUBREDDIT_KEY); String subredditNamePrefixed = data.getString(JSONUtils.SUBREDDIT_NAME_PREFIX_KEY); String author = data.getString(JSONUtils.AUTHOR_KEY); + StringBuilder authorFlairHTMLBuilder = new StringBuilder(); + if (data.has(JSONUtils.AUTHOR_FLAIR_RICHTEXT_KEY)) { + JSONArray flairArray = data.getJSONArray(JSONUtils.AUTHOR_FLAIR_RICHTEXT_KEY); + for (int i = 0; i < flairArray.length(); i++) { + JSONObject flairObject = flairArray.getJSONObject(i); + String e = flairObject.getString(JSONUtils.E_KEY); + if (e.equals("text")) { + authorFlairHTMLBuilder.append(flairObject.getString(JSONUtils.T_KEY)); + } else if (e.equals("emoji")) { + authorFlairHTMLBuilder.append(""); + } + } + } + String authorFlair = data.isNull(JSONUtils.AUTHOR_FLAIR_TEXT_KEY) ? "" : data.getString(JSONUtils.AUTHOR_FLAIR_TEXT_KEY); long postTime = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000; String title = data.getString(JSONUtils.TITLE_KEY); int score = data.getInt(JSONUtils.SCORE_KEY); @@ -71,10 +85,10 @@ public class ParsePost { JSONArray icons = award.getJSONArray(JSONUtils.RESIZED_ICONS_KEY); if (icons.length() > 4) { String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY); - awardingsBuilder.append("").append("x").append(count).append(" "); + awardingsBuilder.append(" ").append("x").append(count).append(" "); } else if (icons.length() > 0) { String iconUrl = icons.getJSONObject(icons.length() - 1).getString(JSONUtils.URL_KEY); - awardingsBuilder.append("").append("x").append(count).append(" "); + awardingsBuilder.append(" ").append("x").append(count).append(" "); } } @@ -115,24 +129,25 @@ public class ParsePost { data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); Post crosspostParent = parseBasicData(data, locale); Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, - author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl, - previewWidth, previewHeight, score, voteType, nComments, flair, - awardingsBuilder.toString(), hidden, spoiler, nsfw, stickied, archived, locked, - saved, true); + author, authorFlair, authorFlairHTMLBuilder.toString(), formattedPostTime, + postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight, + score, voteType, nComments, flair, awardingsBuilder.toString(), hidden, spoiler, + nsfw, stickied, archived, locked, saved, true); post.setCrosspostParentId(crosspostParent.getId()); return post; } else { return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, - author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl, - previewWidth, previewHeight, score, voteType, nComments, flair, - awardingsBuilder.toString(), hidden, spoiler, nsfw, stickied, archived, locked, - saved, false); + author, authorFlair, authorFlairHTMLBuilder.toString(), formattedPostTime, + postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight, + score, voteType, nComments, flair, awardingsBuilder.toString(), hidden, spoiler, + nsfw, stickied, archived, locked, saved, false); } } private static Post parseData(JSONObject data, String permalink, String id, String fullName, String subredditName, String subredditNamePrefixed, String author, - String formattedPostTime, long postTimeMillis, String title, String previewUrl, + String authorFlair, String authorFlairHTML, String formattedPostTime, + long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl, int previewWidth, int previewHeight, int score, int voteType, int nComments, String flair, String awards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, @@ -146,7 +161,8 @@ public class ParsePost { if (url.contains(permalink)) { //Text post int postType = Post.TEXT_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, permalink, score, postType, voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { @@ -171,18 +187,21 @@ public class ParsePost { int postType = Post.IMAGE_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, - score, postType, voteType, nComments, flair, awards, hidden, spoiler, - nsfw, stickied, archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + url, thumbnailPreviewUrl, url, permalink, score, postType, voteType, + nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { //No preview link post int postType = Post.NO_PREVIEW_LINK_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, - title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType, - nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, + title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, + voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -203,9 +222,11 @@ public class ParsePost { String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString(); String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY); - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, - title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, - nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, + nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, + saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -221,9 +242,10 @@ public class ParsePost { .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY); post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, permalink, score, - postType, voteType, nComments, flair, awards, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, + nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -234,9 +256,10 @@ public class ParsePost { int postType = Post.IMAGE_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, - score, postType, voteType, nComments, flair, awards, hidden, spoiler, - nsfw, stickied, archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, + title, url, thumbnailPreviewUrl, url, permalink, score, postType, + voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -244,8 +267,9 @@ public class ParsePost { //Gif post int postType = Post.GIF_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, - score, postType, voteType, nComments, flair, awards, hidden, spoiler, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, + title, previewUrl, thumbnailPreviewUrl, url, permalink, score, + postType, voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); @@ -257,9 +281,10 @@ public class ParsePost { int postType = Post.TEXT_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, permalink, score, postType, - voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, + title, permalink, score, postType, voteType, nComments, flair, + awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, + isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -285,8 +310,9 @@ public class ParsePost { int postType = Post.LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, - score, postType, voteType, nComments, flair, awards, hidden, spoiler, + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, + title, previewUrl, thumbnailPreviewUrl, url, permalink, score, + postType, voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); @@ -305,9 +331,10 @@ public class ParsePost { int postType = Post.IMAGE_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, - score, postType, voteType, nComments, flair, awards, hidden, spoiler, - nsfw, stickied, archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, + voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { @@ -315,9 +342,10 @@ public class ParsePost { int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, score, - postType, voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost); + authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title, + url, thumbnailPreviewUrl, url, permalink, score, postType, voteType, + nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived, + locked, saved, isCrosspost); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java index a224ee24..d16a19a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java @@ -36,6 +36,8 @@ public class Post implements Parcelable { private String author; private String authorNamePrefixed; private String authorIconUrl; + private String authorFlair; + private String authorFlairHTML; private String postTime; private String title; private String selfText; @@ -67,17 +69,19 @@ public class Post implements Parcelable { private String crosspostParentId; public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, - String author, String postTime, long postTimeMillis, String title, String previewUrl, - String thumbnailPreviewUrl, String permalink, int score, int postType, - int voteType, int nComments, String flair, String awards, boolean hidden, - boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, - boolean saved, boolean isCrosspost) { + String author, String authorFlair, String authorFlairHTML, String postTime, + long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl, + String permalink, int score, int postType, int voteType, int nComments, String flair, + String awards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, + boolean archived, boolean locked, boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; this.authorNamePrefixed = "u/" + author; + this.authorFlair = authorFlair; + this.authorFlairHTML = authorFlairHTML; this.postTime = postTime; this.postTimeMillis = postTimeMillis; this.title = title; @@ -101,17 +105,19 @@ public class Post implements Parcelable { } public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, - String author, String postTime, long postTimeMillis, String title, String previewUrl, - String thumbnailPreviewUrl, String url, String permalink, int score, - int postType, int voteType, int nComments, String flair, String awards, - boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, - boolean locked, boolean saved, boolean isCrosspost) { + String author, String authorFlair, String authorFlairHTML, String postTime, + long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl, + String url, String permalink, int score, int postType, int voteType, int nComments, + String flair, String awards, boolean hidden, boolean spoiler, boolean nsfw, + boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; this.authorNamePrefixed = "u/" + author; + this.authorFlair = authorFlair; + this.authorFlairHTML = authorFlairHTML; this.postTime = postTime; this.postTimeMillis = postTimeMillis; this.title = title; @@ -136,16 +142,19 @@ public class Post implements Parcelable { } public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, - String author, String postTime, long postTimeMillis, String title, String permalink, - int score, int postType, int voteType, int nComments, String flair, - String awards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, - boolean archived, boolean locked, boolean saved, boolean isCrosspost) { + String author, String authorFlair, String authorFlairHTML, String postTime, + long postTimeMillis, String title, String permalink, int score, int postType, + int voteType, int nComments, String flair, String awards, boolean hidden, + boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, + boolean saved, boolean isCrosspost) { this.id = id; this.fullName = fullName; this.subredditName = subredditName; this.subredditNamePrefixed = subredditNamePrefixed; this.author = author; this.authorNamePrefixed = "u/" + author; + this.authorFlair = authorFlair; + this.authorFlairHTML = authorFlairHTML; this.postTime = postTime; this.postTimeMillis = postTimeMillis; this.title = title; @@ -174,6 +183,8 @@ public class Post implements Parcelable { subredditIconUrl = in.readString(); author = in.readString(); authorNamePrefixed = in.readString(); + authorFlair = in.readString(); + authorFlairHTML = in.readString(); authorIconUrl = in.readString(); postTime = in.readString(); postTimeMillis = in.readLong(); @@ -238,6 +249,14 @@ public class Post implements Parcelable { return authorNamePrefixed; } + public String getAuthorFlair() { + return authorFlair; + } + + public String getAuthorFlairHTML() { + return authorFlairHTML; + } + public String getAuthorIconUrl() { return authorIconUrl; } @@ -444,6 +463,8 @@ public class Post implements Parcelable { parcel.writeString(subredditIconUrl); parcel.writeString(author); parcel.writeString(authorNamePrefixed); + parcel.writeString(authorFlair); + parcel.writeString(authorFlairHTML); parcel.writeString(authorIconUrl); parcel.writeString(postTime); parcel.writeLong(postTimeMillis); -- cgit v1.2.3