Add an option to show rounded number of votes.

This commit is contained in:
Alex Ning 2020-02-21 00:27:04 +08:00
parent b06c24402b
commit a54a3395f8
13 changed files with 149 additions and 52 deletions

View File

@ -177,6 +177,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private boolean mSwipeUpToHideFab; private boolean mSwipeUpToHideFab;
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter; private CommentAndPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller mSmoothScroller; private RecyclerView.SmoothScroller mSmoothScroller;
@ -265,6 +266,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false); mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false); mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
mGlide = Glide.with(this); mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale; mLocale = getResources().getConfiguration().locale;
@ -511,6 +513,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {
@ -634,6 +637,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider, mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {

View File

@ -124,6 +124,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mExpandChildren; private boolean mExpandChildren;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading; private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed; private boolean isInitiallyLoadingFailed;
@ -140,6 +141,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String singleCommentId, boolean isSingleCommentThreadMode, String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider, boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider,
boolean showAbsoluteNumberOfVotes,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity; mActivity = activity;
mRetrofit = retrofit; mRetrofit = retrofit;
@ -231,6 +233,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren; mExpandChildren = expandChildren;
mShowCommentDivider = showCommentDivider; mShowCommentDivider = showCommentDivider;
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true; isInitiallyLoading = true;
isInitiallyLoadingFailed = false; isInitiallyLoadingFailed = false;
@ -484,8 +487,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.GONE); ((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
} }
String scoreWithVote = Integer.toString(mPost.getScore() + mPost.getVoteType()); ((PostDetailViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType()));
((PostDetailViewHolder) holder).mScoreTextView.setText(scoreWithVote);
((PostDetailViewHolder) holder).mTypeTextView.setOnClickListener(view -> { ((PostDetailViewHolder) holder).mTypeTextView.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredThingActivity.class); Intent intent = new Intent(mActivity, FilteredThingActivity.class);
@ -742,7 +744,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); mCommentMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
((CommentViewHolder) holder).itemView.setPadding(comment.getDepth() * 8, 0, 0, 0); ((CommentViewHolder) holder).itemView.setPadding(comment.getDepth() * 8, 0, 0, 0);
if (comment.getDepth() > 0) { if (comment.getDepth() > 0) {
@ -894,7 +897,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -910,7 +914,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
((CommentViewHolder) holder).downVoteButton.clearColorFilter(); ((CommentViewHolder) holder).downVoteButton.clearColorFilter();
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
} }
@Override @Override
@ -949,7 +954,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((CommentViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -965,7 +971,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
((CommentViewHolder) holder).upVoteButton.clearColorFilter(); ((CommentViewHolder) holder).upVoteButton.clearColorFilter();
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
} }
@Override @Override
@ -1784,7 +1791,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost); mCommentRecyclerViewAdapterCallback.updatePost(mPost);
@ -1802,7 +1810,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
mDownvoteButton.clearColorFilter(); mDownvoteButton.clearColorFilter();
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost); mCommentRecyclerViewAdapterCallback.updatePost(mPost);
} }
@ -1811,7 +1820,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType); mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType)); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter); mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter); mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor); mScoreTextView.setTextColor(previousScoreTextViewColor);
@ -1855,7 +1865,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); mScoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost); mCommentRecyclerViewAdapterCallback.updatePost(mPost);
@ -1873,7 +1884,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
mUpvoteButton.clearColorFilter(); mUpvoteButton.clearColorFilter();
mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType())); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost); mCommentRecyclerViewAdapterCallback.updatePost(mPost);
} }
@ -1882,7 +1894,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType); mPost.setVoteType(previousVoteType);
mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType)); mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter); mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter); mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor); mScoreTextView.setTextColor(previousScoreTextViewColor);

View File

@ -71,13 +71,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
private NetworkState networkState; private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName, String accessToken, String accountName,
boolean voteButtonsOnTheRight, boolean showElapsedTime, boolean voteButtonsOnTheRight, boolean showElapsedTime,
boolean showCommentDivider, boolean showCommentDivider, boolean showAbsoluteNumberOfVotes,
RetryLoadingMoreCallback retryLoadingMoreCallback) { RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
mContext = context; mContext = context;
@ -112,6 +113,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mShowCommentDivider = showCommentDivider; mShowCommentDivider = showCommentDivider;
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mRetryLoadingMoreCallback = retryLoadingMoreCallback; mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme); mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent); mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@ -161,7 +163,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown()); mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentMarkdown());
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
switch (comment.getVoteType()) { switch (comment.getVoteType()) {
case CommentData.VOTE_TYPE_UPVOTE: case CommentData.VOTE_TYPE_UPVOTE:
@ -228,7 +231,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor));
} }
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -244,7 +248,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
} }
((DataViewHolder) holder).downvoteButton.clearColorFilter(); ((DataViewHolder) holder).downvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
} }
@Override @Override
@ -278,7 +283,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor)); ((DataViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mContext, R.color.defaultTextColor));
} }
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -294,7 +300,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
} }
((DataViewHolder) holder).upvoteButton.clearColorFilter(); ((DataViewHolder) holder).upvoteButton.clearColorFilter();
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
} }
@Override @Override

View File

@ -105,6 +105,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowDividerInCompactLayout; private boolean mShowDividerInCompactLayout;
private boolean mShowAbsoluteNumberOfVotes;
private NetworkState networkState; private NetworkState networkState;
private Callback mCallback; private Callback mCallback;
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment; private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
@ -113,7 +114,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, RedditDataRoomDatabase redditDataRoomDatabase, String accessToken,
int postType, int postLayout, boolean displaySubredditName, int postType, int postLayout, boolean displaySubredditName,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean showDividerInCompactLayout, Callback callback) { boolean showElapsedTime, boolean showDividerInCompactLayout,
boolean showAbsoluteNumberOfVotes, Callback callback) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
if (activity != null) { if (activity != null) {
mActivity = activity; mActivity = activity;
@ -127,6 +129,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime; mShowElapsedTime = showElapsedTime;
mShowDividerInCompactLayout = showDividerInCompactLayout; mShowDividerInCompactLayout = showDividerInCompactLayout;
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mPostLayout = postLayout; mPostLayout = postLayout;
mScale = activity.getResources().getDisplayMetrics().density; mScale = activity.getResources().getDisplayMetrics().density;
mGlide = Glide.with(mActivity.getApplicationContext()); mGlide = Glide.with(mActivity.getApplicationContext());
@ -351,7 +354,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostViewHolder) holder).titleTextView.setText(title); ((PostViewHolder) holder).titleTextView.setText(title);
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
if (gilded > 0) { if (gilded > 0) {
((PostViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE); ((PostViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
@ -558,7 +561,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -575,7 +578,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostViewHolder) holder).downvoteButton.clearColorFilter(); ((PostViewHolder) holder).downvoteButton.clearColorFilter();
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -584,7 +587,7 @@ 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);
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType)); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
((PostViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); ((PostViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((PostViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); ((PostViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor); ((PostViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@ -629,7 +632,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((PostViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -646,7 +649,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostViewHolder) holder).upvoteButton.clearColorFilter(); ((PostViewHolder) holder).upvoteButton.clearColorFilter();
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -655,7 +658,7 @@ 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);
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType)); ((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
((PostViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); ((PostViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((PostViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); ((PostViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor); ((PostViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@ -906,7 +909,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostCompactViewHolder) holder).titleTextView.setText(title); ((PostCompactViewHolder) holder).titleTextView.setText(title);
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
if (gilded > 0) { if (gilded > 0) {
((PostCompactViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE); ((PostCompactViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
@ -1104,7 +1107,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -1121,7 +1124,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostCompactViewHolder) holder).downvoteButton.clearColorFilter(); ((PostCompactViewHolder) holder).downvoteButton.clearColorFilter();
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1130,7 +1133,7 @@ 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);
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType)); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
((PostCompactViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); ((PostCompactViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((PostCompactViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); ((PostCompactViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostCompactViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor); ((PostCompactViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@ -1175,7 +1178,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor)); ((PostCompactViewHolder) holder).scoreTextView.setTextColor(ContextCompat.getColor(mActivity, R.color.defaultTextColor));
} }
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() { VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override @Override
@ -1192,7 +1195,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
((PostCompactViewHolder) holder).upvoteButton.clearColorFilter(); ((PostCompactViewHolder) holder).upvoteButton.clearColorFilter();
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post)); EventBus.getDefault().post(new PostUpdateEventToDetailActivity(post));
} }
@ -1201,7 +1204,7 @@ 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);
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType)); ((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + previousVoteType));
((PostCompactViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter); ((PostCompactViewHolder) holder).upvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
((PostCompactViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter); ((PostCompactViewHolder) holder).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostCompactViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor); ((PostCompactViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@ -1395,6 +1398,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mShowDividerInCompactLayout = showDividerInCompactLayout; mShowDividerInCompactLayout = showDividerInCompactLayout;
} }
public void setShowAbsoluteNumberOfVotes(boolean showAbsoluteNumberOfVotes) {
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
}
private boolean hasExtraRow() { private boolean hasExtraRow() {
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS; return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
} }

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.Event;
public class ChangeShowAbsoluteNumberOfVotesEvent {
public boolean showAbsoluteNumberOfVotes;
public ChangeShowAbsoluteNumberOfVotesEvent(boolean showAbsoluteNumberOfVotes) {
this.showAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
}
}

View File

@ -88,6 +88,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private CommentsListingRecyclerViewAdapter mAdapter; private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
public CommentsListingFragment() { public CommentsListingFragment() {
// Required empty public constructor // Required empty public constructor
@ -118,6 +119,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false); mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources); getCurrentAccountAndBindView(resources);
@ -152,7 +154,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME), getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
voteButtonsOnTheRight, mShowElapsedTime, mShowCommentDivider, () -> mCommentViewModel.retryLoadingMore()); voteButtonsOnTheRight, mShowElapsedTime, mShowCommentDivider, mShowAbsoluteNumberOfVotes,
() -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME); String username = getArguments().getString(EXTRA_USERNAME);
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);

View File

@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.Fragment; package ml.docilealligator.infinityforreddit.Fragment;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -55,6 +54,7 @@ import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
@ -323,6 +323,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
boolean showDividerInCompactLayout = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true); boolean showDividerInCompactLayout = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true);
boolean showAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0")); int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
if (postType == PostDataSource.TYPE_SEARCH) { if (postType == PostDataSource.TYPE_SEARCH) {
@ -336,7 +337,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -399,7 +401,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -447,7 +450,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -493,7 +497,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -532,7 +537,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -738,26 +744,34 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe @Subscribe
public void onChangeShowElapsedTime(ChangeShowElapsedTimeEvent event) { public void onChangeShowElapsedTime(ChangeShowElapsedTimeEvent event) {
mAdapter.setShowElapsedTime(event.showElapsedTime); if (mAdapter != null) {
refreshAdapter(); mAdapter.setShowElapsedTime(event.showElapsedTime);
refreshAdapter();
}
} }
@Subscribe @Subscribe
public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) { public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) {
mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight); if (mAdapter != null) {
refreshAdapter(); mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight);
refreshAdapter();
}
} }
@Subscribe @Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
mAdapter.setBlurNSFW(event.needBlurNSFW); if (mAdapter != null) {
refreshAdapter(); mAdapter.setBlurNSFW(event.needBlurNSFW);
refreshAdapter();
}
} }
@Subscribe @Subscribe
public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) { public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
mAdapter.setBlurSpoiler(event.needBlurSpoiler); if (mAdapter != null) {
refreshAdapter(); mAdapter.setBlurSpoiler(event.needBlurSpoiler);
refreshAdapter();
}
} }
@Subscribe @Subscribe
@ -767,8 +781,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe @Subscribe
public void onShowDividerInCompactLayoutPreferenceEvent(ShowDividerInCompactLayoutPreferenceEvent event) { public void onShowDividerInCompactLayoutPreferenceEvent(ShowDividerInCompactLayoutPreferenceEvent event) {
mAdapter.setShowDividerInCompactLayout(event.showDividerInCompactLayout); if (mAdapter != null) {
refreshAdapter(); mAdapter.setShowDividerInCompactLayout(event.showDividerInCompactLayout);
refreshAdapter();
}
} }
@Subscribe @Subscribe
@ -805,6 +821,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
} }
@Subscribe
public void onChangeShowAbsoluteNumberOfVotesEvent(ChangeShowAbsoluteNumberOfVotesEvent changeShowAbsoluteNumberOfVotesEvent) {
if (mAdapter != null) {
mAdapter.setShowAbsoluteNumberOfVotes(changeShowAbsoluteNumberOfVotesEvent.showAbsoluteNumberOfVotes);
refreshAdapter();
}
}
private void refreshAdapter() { private void refreshAdapter() {
int previousPosition = -1; int previousPosition = -1;
if (mLinearLayoutManager != null) { if (mLinearLayoutManager != null) {

View File

@ -17,6 +17,7 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent; import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
@ -48,6 +49,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY); SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES);
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
@ -134,6 +136,13 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
return true; return true;
}); });
} }
if (showAbsoluteNumberOfVotes != null) {
showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue));
return true;
});
}
} }
@Override @Override

View File

@ -76,4 +76,5 @@ public class SharedPreferencesUtils {
public static final String CONFIRM_TO_EXIT = "confirm_to_exit"; public static final String CONFIRM_TO_EXIT = "confirm_to_exit";
public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar"; public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar";
public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider"; public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider";
public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes";
} }

View File

@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit.Utils;
import android.content.Context; import android.content.Context;
import java.util.Locale;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
public class Utils { public class Utils {
@ -60,4 +62,15 @@ public class Utils {
return context.getString(R.string.elapsed_time_years_ago, diff / YEAR_MILLIS); return context.getString(R.string.elapsed_time_years_ago, diff / YEAR_MILLIS);
} }
} }
public static String getNVotes(boolean showAbsoluteNumberOfVotes, int votes) {
if (showAbsoluteNumberOfVotes) {
return Integer.toString(votes);
} else {
if (Math.abs(votes) < 1000) {
return Integer.toString(votes);
}
return String.format(Locale.US, "%.1f", (float) votes / 1000) + "K";
}
}
} }

View File

@ -31,6 +31,7 @@
android:id="@+id/divider_item_load_more_comments_placeholder" android:id="@+id/divider_item_load_more_comments_placeholder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"
android:background="@color/dividerColor" /> android:background="@color/dividerColor"
android:visibility="gone" />
</LinearLayout> </LinearLayout>

View File

@ -309,6 +309,7 @@
<string name="settings_confirm_to_exit">Confirm to Exit</string> <string name="settings_confirm_to_exit">Confirm to Exit</string>
<string name="settings_show_top_level_comments_first_title">Show Top-level Comments First</string> <string name="settings_show_top_level_comments_first_title">Show Top-level Comments First</string>
<string name="settings_show_comment_divider_title">Show comment divider</string> <string name="settings_show_comment_divider_title">Show comment divider</string>
<string name="settings_show_absolute_number_of_votes_title">Show Absolute Number of Votes</string>
<string name="settings_show_elapsed_time">Show Elapsed Time in Posts and Comments</string> <string name="settings_show_elapsed_time">Show Elapsed Time in Posts and Comments</string>
<string name="settings_default_post_layout">Default Post Layout</string> <string name="settings_default_post_layout">Default Post Layout</string>
<string name="settings_show_divider_in_compact_layout">Show Divider in Compact Layout</string> <string name="settings_show_divider_in_compact_layout">Show Divider in Compact Layout</string>

View File

@ -64,4 +64,9 @@
app:key="show_comment_divider" app:key="show_comment_divider"
app:title="@string/settings_show_comment_divider_title" /> app:title="@string/settings_show_comment_divider_title" />
<SwitchPreference
app:defaultValue="true"
app:key="show_absolute_number_of_votes"
app:title="@string/settings_show_absolute_number_of_votes_title" />
</PreferenceScreen> </PreferenceScreen>