aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-18 01:35:45 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-18 01:35:45 +0000
commit38344e305ce213012723870fdc7bea474baf1083 (patch)
treed709d3fd63dc998ccc95870f543c464a4ecc8277
parentcca031399085f433fcbe150af0a1c4a2d46bdfb1 (diff)
downloadinfinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar.gz
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar.bz2
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar.lz
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar.xz
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.tar.zst
infinity-for-reddit-38344e305ce213012723870fdc7bea474baf1083.zip
Save vote state in CommentData
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java16
2 files changed, 25 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
index 5da40e9a..02bc245d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentData.java
@@ -6,6 +6,7 @@ class CommentData {
private String commentTime;
private String commentContent;
private int score;
+ private int voteType;
private boolean isSubmitter;
private String permalink;
private int depth;
@@ -81,4 +82,12 @@ class CommentData {
public boolean isScoreHidden() {
return scoreHidden;
}
+
+ public int getVoteType() {
+ return voteType;
+ }
+
+ public void setVoteType(int voteType) {
+ this.voteType = voteType;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
index 7de223bb..eef1a004 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
@@ -42,6 +42,18 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
((CommentViewHolder) holder).commentTextView.setText(mCommentData.get(position).getCommentContent());
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
+
+ switch (mCommentData.get(position).getVoteType()) {
+ case 1:
+ ((CommentViewHolder) holder).upvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ break;
+ case 2:
+ ((CommentViewHolder) holder).downvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
+ break;
+ }
+
((CommentViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -60,6 +72,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setVoteType(1);
if(isDownvotedBefore) {
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 2);
} else {
@@ -83,6 +96,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setVoteType(0);
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
}
@@ -117,6 +131,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setVoteType(-1);
if(isUpvotedBefore) {
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 2);
} else {
@@ -140,6 +155,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
+ mCommentData.get(position).setVoteType(0);
mCommentData.get(position).setScore(mCommentData.get(position).getScore());
}