Fix wrong vote info showing in posts and comments.

This commit is contained in:
Alex Ning 2020-12-07 22:11:54 +08:00
parent 42957a1aa2
commit f25f75b3d0
2 changed files with 154 additions and 80 deletions

View File

@ -3487,27 +3487,35 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Utils.getNVotes(mShowAbsoluteNumberOfVotes, Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()))); comment.getScore() + comment.getVoteType())));
int position = getAdapterPosition();
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position) { public void onVoteThingSuccess(int position) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_UPVOTE); comment.setVoteType(Comment.VOTE_TYPE_UPVOTE);
upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mUpvotedColor); upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
topScoreTextView.setTextColor(mUpvotedColor); scoreTextView.setTextColor(mUpvotedColor);
topScoreTextView.setTextColor(mUpvotedColor);
}
} else { } else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE); comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mCommentIconAndInfoColor); upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
topScoreTextView.setTextColor(mSecondaryTextColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
}
} }
downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
comment.getScore() + comment.getVoteType())); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
topScoreTextView.setText(mActivity.getString(R.string.top_score, comment.getScore() + comment.getVoteType()));
Utils.getNVotes(mShowAbsoluteNumberOfVotes, topScoreTextView.setText(mActivity.getString(R.string.top_score,
comment.getScore() + comment.getVoteType()))); Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())));
}
} }
@Override @Override
@ -3557,27 +3565,35 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
Utils.getNVotes(mShowAbsoluteNumberOfVotes, Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()))); comment.getScore() + comment.getVoteType())));
int position = getAdapterPosition();
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) { if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE); comment.setVoteType(Comment.VOTE_TYPE_DOWNVOTE);
downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mDownvotedColor); downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
topScoreTextView.setTextColor(mDownvotedColor); scoreTextView.setTextColor(mDownvotedColor);
topScoreTextView.setTextColor(mDownvotedColor);
}
} else { } else {
comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE); comment.setVoteType(Comment.VOTE_TYPE_NO_VOTE);
downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mCommentIconAndInfoColor); downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
topScoreTextView.setTextColor(mSecondaryTextColor); scoreTextView.setTextColor(mCommentIconAndInfoColor);
topScoreTextView.setTextColor(mSecondaryTextColor);
}
} }
upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, upvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
comment.getScore() + comment.getVoteType())); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
topScoreTextView.setText(mActivity.getString(R.string.top_score, comment.getScore() + comment.getVoteType()));
Utils.getNVotes(mShowAbsoluteNumberOfVotes, topScoreTextView.setText(mActivity.getString(R.string.top_score,
comment.getScore() + comment.getVoteType()))); Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType())));
}
} }
@Override @Override
@ -3590,20 +3606,25 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
saveButton.setOnClickListener(view -> { saveButton.setOnClickListener(view -> {
Comment comment = getCurrentComment(this); Comment comment = getCurrentComment(this);
if (comment != null) { if (comment != null) {
int position = getAdapterPosition();
if (comment.isSaved()) { if (comment.isSaved()) {
comment.setSaved(false); comment.setSaved(false);
SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() { SaveThing.unsaveThing(mOauthRetrofit, mAccessToken, comment.getFullName(), new SaveThing.SaveThingListener() {
@Override @Override
public void success() { public void success() {
comment.setSaved(false); comment.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
} }
@Override @Override
public void failed() { public void failed() {
comment.setSaved(true); comment.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
} }
}); });
@ -3613,14 +3634,18 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
@Override @Override
public void success() { public void success() {
comment.setSaved(true); comment.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
} }
@Override @Override
public void failed() { public void failed() {
comment.setSaved(false); comment.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
} }
}); });

View File

@ -1677,19 +1677,25 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
post.setVoteType(1); post.setVoteType(1);
upvoteButton if (currentPosition == position) {
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor); scoreTextView.setTextColor(mUpvotedColor);
}
} else { } else {
post.setVoteType(0); post.setVoteType(0);
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mPostIconAndInfoColor); upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mPostIconAndInfoColor);
}
} }
downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1698,10 +1704,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) { public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
post.setVoteType(previousVoteType); post.setVoteType(previousVoteType);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); if (getAdapterPosition() == position) {
upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor); downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1755,19 +1763,25 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) { if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
post.setVoteType(-1); post.setVoteType(-1);
downvoteButton if (currentPosition == position) {
.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mDownvotedColor); scoreTextView.setTextColor(mDownvotedColor);
}
} else { } else {
post.setVoteType(0); post.setVoteType(0);
downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mPostIconAndInfoColor); downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mPostIconAndInfoColor);
}
} }
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1776,10 +1790,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) { public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
post.setVoteType(previousVoteType); post.setVoteType(previousVoteType);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); if (getAdapterPosition() == position) {
upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor); downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1806,7 +1822,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void success() { public void success() {
post.setSaved(false); post.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1814,7 +1832,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void failed() { public void failed() {
post.setSaved(true); post.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1826,7 +1846,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void success() { public void success() {
post.setSaved(true); post.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1834,7 +1856,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void failed() { public void failed() {
post.setSaved(false); post.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2705,19 +2729,25 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) { if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
post.setVoteType(1); post.setVoteType(1);
upvoteButton if (currentPosition == position) {
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mUpvotedColor); scoreTextView.setTextColor(mUpvotedColor);
}
} else { } else {
post.setVoteType(0); post.setVoteType(0);
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mPostIconAndInfoColor); upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mPostIconAndInfoColor);
}
} }
downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2726,10 +2756,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) { public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
post.setVoteType(previousVoteType); post.setVoteType(previousVoteType);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); if (getAdapterPosition() == position) {
upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor); downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2783,19 +2815,26 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
public void onVoteThingSuccess(int position1) { public void onVoteThingSuccess(int position1) {
int currentPosition = getAdapterPosition();
if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) { if (newVoteType.equals(APIUtils.DIR_DOWNVOTE)) {
post.setVoteType(-1); post.setVoteType(-1);
downvoteButton if (currentPosition == position) {
.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN); downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mDownvotedColor); scoreTextView.setTextColor(mDownvotedColor);
}
} else { } else {
post.setVoteType(0); post.setVoteType(0);
downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setTextColor(mPostIconAndInfoColor); downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setTextColor(mPostIconAndInfoColor);
}
} }
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); if (currentPosition == position) {
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType())); upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2804,10 +2843,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) { public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
post.setVoteType(previousVoteType); post.setVoteType(previousVoteType);
scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType)); if (getAdapterPosition() == position) {
upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor); downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
scoreTextView.setTextColor(previousScoreTextViewColor);
}
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2834,7 +2875,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void success() { public void success() {
post.setSaved(false); post.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_unsaved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2842,7 +2885,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void failed() { public void failed() {
post.setSaved(true); post.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_unsaved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2854,7 +2899,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void success() { public void success() {
post.setSaved(true); post.setSaved(true);
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_saved_success, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -2862,7 +2909,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@Override @Override
public void failed() { public void failed() {
post.setSaved(false); post.setSaved(false);
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp); if (getAdapterPosition() == position) {
saveButton.setImageResource(R.drawable.ic_bookmark_border_grey_24dp);
}
Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.post_saved_failed, Toast.LENGTH_SHORT).show();
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }