aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-02-22 06:32:47 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-02-22 06:32:47 +0000
commit30ce4285c9126ac24b6de3e1342735786204c750 (patch)
tree156956602b49ec8a8e89327d33c619086d04ca1a /app/src/main
parent2dfc2a86b001c2cda0193dd1847cf6b1b298ed0d (diff)
downloadinfinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar.gz
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar.bz2
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar.lz
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar.xz
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.tar.zst
infinity-for-reddit-30ce4285c9126ac24b6de3e1342735786204c750.zip
Show a error message in toast for voting things.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Okhttp3DebugInterceptor.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java11
5 files changed, 25 insertions, 16 deletions
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 450c3486..1ddcf537 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -900,7 +900,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
@@ -957,7 +957,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
@@ -1796,7 +1796,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
@@ -1870,7 +1870,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
@Override
public void onVoteThingSuccess() {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
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 3a7139f0..ee21f521 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
@@ -234,7 +234,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position) {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
@@ -286,7 +286,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
comment.getScore() + comment.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
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 c1c3aca0..f08c39f6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -563,7 +563,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
@@ -634,7 +634,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
@@ -1109,7 +1109,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
@@ -1180,7 +1180,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
- VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
+ VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
@Override
public void onVoteThingSuccess(int position1) {
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Okhttp3DebugInterceptor.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Okhttp3DebugInterceptor.java
index 3443fdc6..0392415b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Okhttp3DebugInterceptor.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Okhttp3DebugInterceptor.java
@@ -1,6 +1,6 @@
package ml.docilealligator.infinityforreddit;
-import android.app.Application;
+import android.content.Context;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
@@ -12,9 +12,9 @@ import okhttp3.Interceptor;
import okhttp3.Response;
public class Okhttp3DebugInterceptor implements Interceptor {
- private Application context;
+ private Context context;
- public Okhttp3DebugInterceptor(Application context) {
+ public Okhttp3DebugInterceptor(Context context) {
this.context = context;
}
@@ -24,7 +24,9 @@ public class Okhttp3DebugInterceptor implements Interceptor {
Response response = chain.proceed(chain.request());
if (!response.isSuccessful()) {
String message = "No body";
- if (response.body() != null) {
+ if (response.code() == 401) {
+ message = "Not authorized";
+ } else if (response.body() != null) {
message = response.body().string();
}
NotificationManagerCompat notificationManager = NotificationUtils.getNotificationManager(context);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
index 5bbbeedf..f1e9a3f1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/VoteThing.java
@@ -1,5 +1,8 @@
package ml.docilealligator.infinityforreddit;
+import android.content.Context;
+import android.widget.Toast;
+
import androidx.annotation.NonNull;
import java.util.HashMap;
@@ -16,7 +19,7 @@ import retrofit2.Retrofit;
public class VoteThing {
- public static void voteThing(final Retrofit retrofit, String accessToken,
+ public static void voteThing(Context context, final Retrofit retrofit, String accessToken,
final VoteThingListener voteThingListener, final String fullName,
final String point, final int position) {
RedditAPI api = retrofit.create(RedditAPI.class);
@@ -34,17 +37,19 @@ public class VoteThing {
voteThingListener.onVoteThingSuccess(position);
} else {
voteThingListener.onVoteThingFail(position);
+ Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
voteThingListener.onVoteThingFail(position);
+ Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
- public static void voteThing(final Retrofit retrofit, String accessToken,
+ public static void voteThing(Context context, final Retrofit retrofit, String accessToken,
final VoteThingWithoutPositionListener voteThingWithoutPositionListener,
final String fullName, final String point) {
RedditAPI api = retrofit.create(RedditAPI.class);
@@ -62,12 +67,14 @@ public class VoteThing {
voteThingWithoutPositionListener.onVoteThingSuccess();
} else {
voteThingWithoutPositionListener.onVoteThingFail();
+ Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
voteThingWithoutPositionListener.onVoteThingFail();
+ Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}