aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java39
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeShowAbsoluteNumberOfVotesEvent.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java56
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java13
10 files changed, 141 insertions, 51 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index 65711954..d8950f2c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -177,6 +177,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private boolean mSwipeUpToHideFab;
private boolean mExpandChildren;
private boolean mShowCommentDivider;
+ private boolean mShowAbsoluteNumberOfVotes;
private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter;
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);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
+ mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
@@ -511,6 +513,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
+ mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
@@ -634,6 +637,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
+ mShowAbsoluteNumberOfVotes,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index 82270285..450c3486 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -124,6 +124,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mShowElapsedTime;
private boolean mExpandChildren;
private boolean mShowCommentDivider;
+ private boolean mShowAbsoluteNumberOfVotes;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed;
@@ -140,6 +141,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider,
+ boolean showAbsoluteNumberOfVotes,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
@@ -231,6 +233,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren;
mShowCommentDivider = showCommentDivider;
+ mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
@@ -484,8 +487,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mNSFWTextView.setVisibility(View.GONE);
}
- String scoreWithVote = Integer.toString(mPost.getScore() + mPost.getVoteType());
- ((PostDetailViewHolder) holder).mScoreTextView.setText(scoreWithVote);
+ ((PostDetailViewHolder) holder).mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, mPost.getScore() + mPost.getVoteType()));
((PostDetailViewHolder) holder).mTypeTextView.setOnClickListener(view -> {
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());
- ((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);
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.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() {
@Override
@@ -910,7 +914,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
((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
@@ -949,7 +954,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((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() {
@Override
@@ -965,7 +971,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
((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
@@ -1784,7 +1791,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
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);
@@ -1802,7 +1810,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
mDownvoteButton.clearColorFilter();
- mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
}
@@ -1811,7 +1820,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
- mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
@@ -1855,7 +1865,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
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);
@@ -1873,7 +1884,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
mUpvoteButton.clearColorFilter();
- mScoreTextView.setText(Integer.toString(mPost.getScore() + mPost.getVoteType()));
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + mPost.getVoteType()));
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
}
@@ -1882,7 +1894,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
public void onVoteThingFail() {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
mPost.setVoteType(previousVoteType);
- mScoreTextView.setText(Integer.toString(mPost.getScore() + previousVoteType));
+ mScoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
+ mPost.getScore() + previousVoteType));
mUpvoteButton.setColorFilter(previousUpvoteButtonColorFilter);
mDownvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
mScoreTextView.setTextColor(previousScoreTextViewColor);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
index 1221fff8..3a7139f0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
@@ -71,13 +71,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
+ private boolean mShowAbsoluteNumberOfVotes;
private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName,
boolean voteButtonsOnTheRight, boolean showElapsedTime,
- boolean showCommentDivider,
+ boolean showCommentDivider, boolean showAbsoluteNumberOfVotes,
RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
mContext = context;
@@ -112,6 +113,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mShowCommentDivider = showCommentDivider;
+ mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@@ -161,7 +163,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
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()) {
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.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() {
@Override
@@ -244,7 +248,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
((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
@@ -278,7 +283,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((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() {
@Override
@@ -294,7 +300,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}
((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
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 d87a6617..10e662e1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -105,6 +105,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mNeedBlurSpoiler;
private boolean mShowElapsedTime;
private boolean mShowDividerInCompactLayout;
+ private boolean mShowAbsoluteNumberOfVotes;
private NetworkState networkState;
private Callback mCallback;
private ShareLinkBottomSheetFragment mShareLinkBottomSheetFragment;
@@ -113,7 +114,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
RedditDataRoomDatabase redditDataRoomDatabase, String accessToken,
int postType, int postLayout, boolean displaySubredditName,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
- boolean showElapsedTime, boolean showDividerInCompactLayout, Callback callback) {
+ boolean showElapsedTime, boolean showDividerInCompactLayout,
+ boolean showAbsoluteNumberOfVotes, Callback callback) {
super(DIFF_CALLBACK);
if (activity != null) {
mActivity = activity;
@@ -127,6 +129,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mShowDividerInCompactLayout = showDividerInCompactLayout;
+ mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mPostLayout = postLayout;
mScale = activity.getResources().getDisplayMetrics().density;
mGlide = Glide.with(mActivity.getApplicationContext());
@@ -351,7 +354,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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) {
((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.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() {
@Override
@@ -575,7 +578,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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));
}
@@ -584,7 +587,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
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).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((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.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() {
@Override
@@ -646,7 +649,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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));
}
@@ -655,7 +658,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
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).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@@ -906,7 +909,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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) {
((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.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() {
@Override
@@ -1121,7 +1124,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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));
}
@@ -1130,7 +1133,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
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).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((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.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() {
@Override
@@ -1192,7 +1195,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
((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));
}
@@ -1201,7 +1204,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public void onVoteThingFail(int position1) {
Toast.makeText(mActivity, R.string.vote_failed, Toast.LENGTH_SHORT).show();
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).downvoteButton.setColorFilter(previousDownvoteButtonColorFilter);
((PostCompactViewHolder) holder).scoreTextView.setTextColor(previousScoreTextViewColor);
@@ -1395,6 +1398,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mShowDividerInCompactLayout = showDividerInCompactLayout;
}
+ public void setShowAbsoluteNumberOfVotes(boolean showAbsoluteNumberOfVotes) {
+ mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
+ }
+
private boolean hasExtraRow() {
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeShowAbsoluteNumberOfVotesEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeShowAbsoluteNumberOfVotesEvent.java
new file mode 100644
index 00000000..c0547c20
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangeShowAbsoluteNumberOfVotesEvent.java
@@ -0,0 +1,9 @@
+package ml.docilealligator.infinityforreddit.Event;
+
+public class ChangeShowAbsoluteNumberOfVotesEvent {
+ public boolean showAbsoluteNumberOfVotes;
+
+ public ChangeShowAbsoluteNumberOfVotesEvent(boolean showAbsoluteNumberOfVotes) {
+ this.showAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
index 11a80379..ba5e94ed 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -88,6 +88,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
+ private boolean mShowAbsoluteNumberOfVotes;
public CommentsListingFragment() {
// Required empty public constructor
@@ -118,6 +119,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
+ mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
if (savedInstanceState == null) {
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);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
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 sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index e309343c..cf434238 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.Fragment;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
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.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
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 showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
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"));
if (postType == PostDataSource.TYPE_SEARCH) {
@@ -336,7 +337,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
- voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() {
+ voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -399,7 +401,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler,
- voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() {
+ voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -447,7 +450,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
- voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() {
+ voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -493,7 +497,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
- voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() {
+ voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -532,7 +537,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
- voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, new PostRecyclerViewAdapter.Callback() {
+ voteButtonsOnTheRight, showElapsedTime, showDividerInCompactLayout, showAbsoluteNumberOfVotes,
+ new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -738,26 +744,34 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe
public void onChangeShowElapsedTime(ChangeShowElapsedTimeEvent event) {
- mAdapter.setShowElapsedTime(event.showElapsedTime);
- refreshAdapter();
+ if (mAdapter != null) {
+ mAdapter.setShowElapsedTime(event.showElapsedTime);
+ refreshAdapter();
+ }
}
@Subscribe
public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) {
- mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight);
- refreshAdapter();
+ if (mAdapter != null) {
+ mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight);
+ refreshAdapter();
+ }
}
@Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
- mAdapter.setBlurNSFW(event.needBlurNSFW);
- refreshAdapter();
+ if (mAdapter != null) {
+ mAdapter.setBlurNSFW(event.needBlurNSFW);
+ refreshAdapter();
+ }
}
@Subscribe
public void onChangeSpoilerBlurEvent(ChangeSpoilerBlurEvent event) {
- mAdapter.setBlurSpoiler(event.needBlurSpoiler);
- refreshAdapter();
+ if (mAdapter != null) {
+ mAdapter.setBlurSpoiler(event.needBlurSpoiler);
+ refreshAdapter();
+ }
}
@Subscribe
@@ -767,8 +781,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe
public void onShowDividerInCompactLayoutPreferenceEvent(ShowDividerInCompactLayoutPreferenceEvent event) {
- mAdapter.setShowDividerInCompactLayout(event.showDividerInCompactLayout);
- refreshAdapter();
+ if (mAdapter != null) {
+ mAdapter.setShowDividerInCompactLayout(event.showDividerInCompactLayout);
+ refreshAdapter();
+ }
}
@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() {
int previousPosition = -1;
if (mLinearLayoutManager != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
index 4123f276..78634adf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java
@@ -17,6 +17,7 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
+import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
@@ -48,6 +49,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
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;
@@ -134,6 +136,13 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
+
+ if (showAbsoluteNumberOfVotes != null) {
+ showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue));
+ return true;
+ });
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index 85c1f9f9..0ff474bd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -76,4 +76,5 @@ public class SharedPreferencesUtils {
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 SHOW_COMMENT_DIVIDER = "show_comment_divider";
+ public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes";
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
index e39d6e35..552f8515 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
@@ -2,6 +2,8 @@ package ml.docilealligator.infinityforreddit.Utils;
import android.content.Context;
+import java.util.Locale;
+
import ml.docilealligator.infinityforreddit.R;
public class Utils {
@@ -60,4 +62,15 @@ public class Utils {
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";
+ }
+ }
}