aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/build.gradle10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java159
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 80 insertions, 90 deletions
diff --git a/app/build.gradle b/app/build.gradle
index 8e175db8..a8524124 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -33,14 +33,14 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
- implementation 'androidx.appcompat:appcompat:1.1.0-alpha02'
- implementation 'com.google.android.material:material:1.1.0-alpha03'
+ implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
+ implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
testImplementation 'junit:junit:4.12'
- androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
- androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
+ androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
implementation 'com.google.android.exoplayer:exoplayer:2.7.0'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.7.0'
implementation 'androidx.browser:browser:1.0.0'
@@ -48,7 +48,7 @@ dependencies {
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.pwittchen:swipe-rx2:0.3.0'
- annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
+ annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
annotationProcessor "androidx.room:room-compiler:$rootProject.roomVersion"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 722969ed..9ab843f3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -378,114 +378,103 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
}
((DataViewHolder) holder).upvoteButton.setOnClickListener(view -> {
- final boolean isDownvotedBefore = ((DataViewHolder) holder).downvoteButton.getColorFilter() != null;
+ ColorFilter upvoteButtonColorFilter = ((DataViewHolder) holder).upvoteButton.getColorFilter();
+ ColorFilter downvoteButtonColorFilter = ((DataViewHolder) holder).downvoteButton.getColorFilter();
+ int previousVoteType = post.getVoteType();
+ String newVoteType;
- final ColorFilter downvoteButtonColorFilter = ((DataViewHolder) holder).downvoteButton.getColorFilter();
((DataViewHolder) holder).downvoteButton.clearColorFilter();
- if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
- ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
- if(isDownvotedBefore) {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + 2));
- } else {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + 1));
- }
-
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position1) {
- post.setVoteType(1);
- if(isDownvotedBefore) {
- post.setScore(post.getScore() + 2);
- } else {
- post.setScore(post.getScore() + 1);
- }
- }
-
- @Override
- public void onVoteThingFail(int position1) {
- Toast.makeText(mContext, "Cannot upvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).upvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore()));
- ((DataViewHolder) holder).downvoteButton.setColorFilter(downvoteButtonColorFilter);
- }
- }, id, RedditUtils.DIR_UPVOTE, holder.getAdapterPosition());
+ if(upvoteButtonColorFilter == null) {
+ //Not upvoted before
+ post.setVoteType(1);
+ newVoteType = RedditUtils.DIR_UPVOTE;
} else {
//Upvoted before
+ post.setVoteType(0);
+ newVoteType = RedditUtils.DIR_UNVOTE;
+ }
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+
+ if(((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
+ ((DataViewHolder) holder).upvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
+ } else {
((DataViewHolder) holder).upvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() - 1));
+ }
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position1) {
+ VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position1) {
+ if(newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
+ post.setVoteType(1);
+ } else {
post.setVoteType(0);
- post.setScore(post.getScore() - 1);
}
- @Override
- public void onVoteThingFail(int position1) {
- Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + 1));
- ((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
- post.setScore(post.getScore() + 1);
- }
- }, id, RedditUtils.DIR_UNVOTE, holder.getAdapterPosition());
- }
+ ((DataViewHolder) holder).downvoteButton.clearColorFilter();
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+ }
+
+ @Override
+ public void onVoteThingFail(int position1) {
+ Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(downvoteButtonColorFilter);
+ }
+ }, id, newVoteType, holder.getAdapterPosition());
});
((DataViewHolder) holder).downvoteButton.setOnClickListener(view -> {
- final boolean isUpvotedBefore = ((DataViewHolder) holder).upvoteButton.getColorFilter() != null;
+ ColorFilter upvoteButtonColorFilter = ((DataViewHolder) holder).upvoteButton.getColorFilter();
+ ColorFilter downvoteButtonColorFilter = ((DataViewHolder) holder).downvoteButton.getColorFilter();
+
+ int previousVoteType = post.getVoteType();
+ String newVoteType;
- final ColorFilter upvoteButtonColorFilter = ((DataViewHolder) holder).upvoteButton.getColorFilter();
((DataViewHolder) holder).upvoteButton.clearColorFilter();
- if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
- ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
- if (isUpvotedBefore) {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() - 2));
- } else {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() - 1));
- }
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position12) {
- post.setVoteType(-1);
- if(isUpvotedBefore) {
- post.setScore(post.getScore() - 2);
- } else {
- post.setScore(post.getScore() - 1);
- }
- }
+ if(downvoteButtonColorFilter == null) {
+ //Not downvoted before
+ post.setVoteType(-1);
+ newVoteType = RedditUtils.DIR_DOWNVOTE;
+ } else {
+ //downvoted before
+ post.setVoteType(0);
+ newVoteType = RedditUtils.DIR_UNVOTE;
+ }
- @Override
- public void onVoteThingFail(int position12) {
- Toast.makeText(mContext, "Cannot downvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).downvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore()));
- ((DataViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
- }
- }, id, RedditUtils.DIR_DOWNVOTE, holder.getAdapterPosition());
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+
+ if(((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
+ ((DataViewHolder) holder).downvoteButton
+ .setColorFilter(ContextCompat.getColor(mContext, R.color.colorAccent), android.graphics.PorterDuff.Mode.SRC_IN);
} else {
- //Down voted before
((DataViewHolder) holder).downvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + 1));
+ }
- VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
- @Override
- public void onVoteThingSuccess(int position12) {
+ VoteThing.voteThing(mOauthRetrofit, mSharedPreferences, new VoteThing.VoteThingListener() {
+ @Override
+ public void onVoteThingSuccess(int position1) {
+ if(newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
+ post.setVoteType(-1);
+ } else {
post.setVoteType(0);
- post.setScore(post.getScore());
}
- @Override
- public void onVoteThingFail(int position12) {
- Toast.makeText(mContext, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
- ((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore()));
- post.setScore(post.getScore());
- }
- }, id, RedditUtils.DIR_UNVOTE, holder.getAdapterPosition());
- }
+ ((DataViewHolder) holder).upvoteButton.clearColorFilter();
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
+ }
+
+ @Override
+ public void onVoteThingFail(int position1) {
+ Toast.makeText(mContext, R.string.vote_failed, Toast.LENGTH_SHORT).show();
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + previousVoteType));
+ ((DataViewHolder) holder).upvoteButton.setColorFilter(upvoteButtonColorFilter);
+ ((DataViewHolder) holder).downvoteButton.setColorFilter(downvoteButtonColorFilter);
+ }
+ }, id, newVoteType, holder.getAdapterPosition());
});
((DataViewHolder) holder).shareButton.setOnClickListener(view -> {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 360767c5..85fc75f9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -25,6 +25,7 @@
<string name="retry">Retry</string>
<string name="comments">Comments</string>
<string name="no_comments_yet">No comments yet. Write a comment?</string>
+ <string name="vote_failed">Vote failed</string>
<string name="nsfw">NSFW</string>
<string name="karma_info">Karma: %1$d</string>