mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-03-28 04:15:29 +01:00
Save vote state in CommentData
This commit is contained in:
parent
cca0313990
commit
38344e305c
@ -6,6 +6,7 @@ class CommentData {
|
|||||||
private String commentTime;
|
private String commentTime;
|
||||||
private String commentContent;
|
private String commentContent;
|
||||||
private int score;
|
private int score;
|
||||||
|
private int voteType;
|
||||||
private boolean isSubmitter;
|
private boolean isSubmitter;
|
||||||
private String permalink;
|
private String permalink;
|
||||||
private int depth;
|
private int depth;
|
||||||
@ -81,4 +82,12 @@ class CommentData {
|
|||||||
public boolean isScoreHidden() {
|
public boolean isScoreHidden() {
|
||||||
return scoreHidden;
|
return scoreHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getVoteType() {
|
||||||
|
return voteType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVoteType(int voteType) {
|
||||||
|
this.voteType = voteType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,18 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
|
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
|
||||||
((CommentViewHolder) holder).commentTextView.setText(mCommentData.get(position).getCommentContent());
|
((CommentViewHolder) holder).commentTextView.setText(mCommentData.get(position).getCommentContent());
|
||||||
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
|
((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() {
|
((CommentViewHolder) holder).upvoteButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
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() {
|
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
|
mCommentData.get(position).setVoteType(1);
|
||||||
if(isDownvotedBefore) {
|
if(isDownvotedBefore) {
|
||||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 2);
|
mCommentData.get(position).setScore(mCommentData.get(position).getScore() + 2);
|
||||||
} else {
|
} else {
|
||||||
@ -83,6 +96,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
|
mCommentData.get(position).setVoteType(0);
|
||||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 1);
|
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() {
|
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
|
mCommentData.get(position).setVoteType(-1);
|
||||||
if(isUpvotedBefore) {
|
if(isUpvotedBefore) {
|
||||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 2);
|
mCommentData.get(position).setScore(mCommentData.get(position).getScore() - 2);
|
||||||
} else {
|
} else {
|
||||||
@ -140,6 +155,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||||||
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
|
mCommentData.get(position).setVoteType(0);
|
||||||
mCommentData.get(position).setScore(mCommentData.get(position).getScore());
|
mCommentData.get(position).setScore(mCommentData.get(position).getScore());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user