aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-04-18 06:00:37 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-04-18 06:00:37 +0000
commit2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2 (patch)
tree4ab15042351e701cfd5eead28a494f2215ec11e9 /app/src/main/java/ml
parentbde2220d91774337fba60cfdcc4324005b878736 (diff)
downloadinfinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar.gz
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar.bz2
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar.lz
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar.xz
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.tar.zst
infinity-for-reddit-2f72e654eb9b3f92fc03a5b877a4ebcacbdcdab2.zip
Show the number of awards in PostRecyclerView instead.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java41
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java16
3 files changed, 42 insertions, 27 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index ca001e85..fd9b8f44 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Adapter;
import android.content.Intent;
import android.content.res.ColorStateList;
+import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
@@ -242,7 +243,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
boolean nsfw = post.isNSFW();
boolean spoiler = post.isSpoiler();
String flair = post.getFlair();
- String awards = post.getAwards();
+ int nAwards = post.getnAwards();
boolean isArchived = post.isArchived();
((PostViewHolder) holder).cardView.setOnClickListener(view -> {
@@ -451,9 +452,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).flairTextView.setText(flairHTML);
}
- if (awards != null && !awards.equals("")) {
+ if (nAwards > 0) {
((PostViewHolder) holder).awardsTextView.setVisibility(View.VISIBLE);
- Utils.setHTMLWithImageToTextView(((PostViewHolder) holder).awardsTextView, awards);
+ ((PostViewHolder) holder).awardsTextView.setText(mActivity.getString(R.string.n_awards, nAwards));
}
switch (voteType) {
@@ -1604,7 +1605,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@BindView(R.id.flair_custom_text_view_item_post)
CustomTextView flairTextView;
@BindView(R.id.awards_text_view_item_post)
- TextView awardsTextView;
+ CustomTextView awardsTextView;
@BindView(R.id.link_text_view_item_post)
TextView linkTextView;
@BindView(R.id.image_view_wrapper_item_post)
@@ -1684,7 +1685,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
archivedImageView.setColorFilter(mArchivedIconTint, PorterDuff.Mode.SRC_IN);
lockedImageView.setColorFilter(mLockedIconTint, PorterDuff.Mode.SRC_IN);
crosspostImageView.setColorFilter(mCrosspostIconTint, PorterDuff.Mode.SRC_IN);
- awardsTextView.setTextColor(mSecondaryTextColor);
+ awardsTextView.setBackgroundColor(Color.parseColor("#EEAB02"));
+ awardsTextView.setTextColor(Color.parseColor("#FFFFFF"));
linkTextView.setTextColor(mSecondaryTextColor);
progressBar.setIndeterminateTintList(ColorStateList.valueOf(mColorAccent));
noPreviewLinkImageView.setBackgroundColor(mNoPreviewLinkBackgroundColor);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index b8cd4977..3a4845e1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -79,9 +79,11 @@ public class ParsePost {
String flair = postFlairHTMLBuilder.toString();
StringBuilder awardingsBuilder = new StringBuilder();
JSONArray awardingsArray = data.getJSONArray(JSONUtils.ALL_AWARDINGS_KEY);
+ int nAwards = 0;
for (int i = 0; i < awardingsArray.length(); i++) {
JSONObject award = awardingsArray.getJSONObject(i);
int count = award.getInt(JSONUtils.COUNT_KEY);
+ nAwards += count;
JSONArray icons = award.getJSONArray(JSONUtils.RESIZED_ICONS_KEY);
if (icons.length() > 4) {
String iconUrl = icons.getJSONObject(3).getString(JSONUtils.URL_KEY);
@@ -131,16 +133,16 @@ public class ParsePost {
Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
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);
+ score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
+ spoiler, nsfw, stickied, archived, locked, saved, true);
post.setCrosspostParentId(crosspostParent.getId());
return post;
} else {
return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
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);
+ score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
+ spoiler, nsfw, stickied, archived, locked, saved, false);
}
}
@@ -150,8 +152,9 @@ public class ParsePost {
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,
- boolean archived, boolean locked, boolean saved, boolean isCrosspost) throws JSONException {
+ String awards, int nAwards, boolean hidden, boolean spoiler,
+ boolean nsfw, boolean stickied, boolean archived, boolean locked,
+ boolean saved, boolean isCrosspost) throws JSONException {
Post post;
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
@@ -163,7 +166,7 @@ public class ParsePost {
int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
- title, permalink, score, postType, voteType, nComments, flair, awards,
+ title, permalink, score, postType, voteType, nComments, flair, awards, nAwards,
hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
@@ -189,7 +192,7 @@ public class ParsePost {
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
- nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived,
+ nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
@@ -200,7 +203,7 @@ public class ParsePost {
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,
+ voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
@@ -225,7 +228,7 @@ public class ParsePost {
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,
+ nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
post.setPreviewWidth(previewWidth);
@@ -244,7 +247,7 @@ public class ParsePost {
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,
+ nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight);
@@ -258,8 +261,8 @@ public class ParsePost {
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
title, url, thumbnailPreviewUrl, url, permalink, score, postType,
- voteType, nComments, flair, awards, hidden, spoiler, nsfw, stickied,
- archived, locked, saved, isCrosspost);
+ voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw,
+ stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight);
@@ -269,7 +272,7 @@ public class ParsePost {
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,
+ postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
@@ -283,8 +286,8 @@ public class ParsePost {
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);
+ awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
+ saved, isCrosspost);
post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight);
@@ -312,7 +315,7 @@ public class ParsePost {
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,
+ postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
@@ -333,7 +336,7 @@ public class ParsePost {
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,
+ voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight);
@@ -344,7 +347,7 @@ public class ParsePost {
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
- nComments, flair, awards, hidden, spoiler, nsfw, stickied, archived,
+ nComments, flair, awards, nAwards, 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 d16a19a1..d8b98ad8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
@@ -51,6 +51,7 @@ public class Post implements Parcelable {
private String permalink;
private String flair;
private String awards;
+ private int nAwards;
private long postTimeMillis;
private int score;
private int postType;
@@ -72,7 +73,7 @@ public class Post implements Parcelable {
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,
+ String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
this.id = id;
this.fullName = fullName;
@@ -94,6 +95,7 @@ public class Post implements Parcelable {
this.nComments = nComments;
this.flair = flair;
this.awards = awards;
+ this.nAwards = nAwards;
this.hidden = hidden;
this.spoiler = spoiler;
this.nsfw = nsfw;
@@ -108,7 +110,7 @@ public class Post implements Parcelable {
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,
+ String flair, String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw,
boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
this.id = id;
this.fullName = fullName;
@@ -131,6 +133,7 @@ public class Post implements Parcelable {
this.nComments = nComments;
this.flair = flair;
this.awards = awards;
+ this.nAwards = nAwards;
this.hidden = hidden;
this.spoiler = spoiler;
this.nsfw = nsfw;
@@ -144,7 +147,7 @@ public class Post implements Parcelable {
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
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,
+ int voteType, int nComments, String flair, String awards, int nAwards, boolean hidden,
boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked,
boolean saved, boolean isCrosspost) {
this.id = id;
@@ -165,6 +168,7 @@ public class Post implements Parcelable {
this.nComments = nComments;
this.flair = flair;
this.awards = awards;
+ this.nAwards = nAwards;
this.hidden = hidden;
this.spoiler = spoiler;
this.nsfw = nsfw;
@@ -200,6 +204,7 @@ public class Post implements Parcelable {
permalink = in.readString();
flair = in.readString();
awards = in.readString();
+ nAwards = in.readInt();
score = in.readInt();
postType = in.readInt();
voteType = in.readInt();
@@ -349,6 +354,10 @@ public class Post implements Parcelable {
return awards;
}
+ public int getnAwards() {
+ return nAwards;
+ }
+
public int getScore() {
return score;
}
@@ -480,6 +489,7 @@ public class Post implements Parcelable {
parcel.writeString(permalink);
parcel.writeString(flair);
parcel.writeString(awards);
+ parcel.writeInt(nAwards);
parcel.writeInt(score);
parcel.writeInt(postType);
parcel.writeInt(voteType);