mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-03-28 04:15:29 +01:00
Show a error message in toast for voting things.
This commit is contained in:
parent
2dfc2a86b0
commit
30ce4285c9
@ -900,7 +900,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
comment.getScore() + comment.getVoteType()));
|
comment.getScore() + comment.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -957,7 +957,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
((CommentViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
comment.getScore() + comment.getVoteType()));
|
comment.getScore() + comment.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
@ -1796,7 +1796,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
|
|
||||||
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -1870,7 +1870,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
|
|||||||
|
|
||||||
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
mCommentRecyclerViewAdapterCallback.updatePost(mPost);
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
VoteThing.voteThing(mActivity, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingWithoutPositionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess() {
|
public void onVoteThingSuccess() {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
|
@ -234,7 +234,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
comment.getScore() + comment.getVoteType()));
|
comment.getScore() + comment.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position) {
|
public void onVoteThingSuccess(int position) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
||||||
@ -286,7 +286,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
|
|||||||
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
((DataViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes,
|
||||||
comment.getScore() + comment.getVoteType()));
|
comment.getScore() + comment.getVoteType()));
|
||||||
|
|
||||||
VoteThing.voteThing(mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
VoteThing.voteThing(mContext, mOauthRetrofit, mAccessToken, new VoteThing.VoteThingListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
|
@ -563,7 +563,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
((PostViewHolder) holder).scoreTextView.setText(Utils.getNVotes(mShowAbsoluteNumberOfVotes, post.getScore() + post.getVoteType()));
|
((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
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
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()));
|
((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
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
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()));
|
((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
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_UPVOTE)) {
|
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()));
|
((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
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
if (newVoteType.equals(RedditUtils.DIR_DOWNVOTE)) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.core.app.NotificationCompat;
|
import androidx.core.app.NotificationCompat;
|
||||||
@ -12,9 +12,9 @@ import okhttp3.Interceptor;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class Okhttp3DebugInterceptor implements Interceptor {
|
public class Okhttp3DebugInterceptor implements Interceptor {
|
||||||
private Application context;
|
private Context context;
|
||||||
|
|
||||||
public Okhttp3DebugInterceptor(Application context) {
|
public Okhttp3DebugInterceptor(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,9 @@ public class Okhttp3DebugInterceptor implements Interceptor {
|
|||||||
Response response = chain.proceed(chain.request());
|
Response response = chain.proceed(chain.request());
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
String message = "No body";
|
String message = "No body";
|
||||||
if (response.body() != null) {
|
if (response.code() == 401) {
|
||||||
|
message = "Not authorized";
|
||||||
|
} else if (response.body() != null) {
|
||||||
message = response.body().string();
|
message = response.body().string();
|
||||||
}
|
}
|
||||||
NotificationManagerCompat notificationManager = NotificationUtils.getNotificationManager(context);
|
NotificationManagerCompat notificationManager = NotificationUtils.getNotificationManager(context);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -16,7 +19,7 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
public class VoteThing {
|
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 VoteThingListener voteThingListener, final String fullName,
|
||||||
final String point, final int position) {
|
final String point, final int position) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
@ -34,17 +37,19 @@ public class VoteThing {
|
|||||||
voteThingListener.onVoteThingSuccess(position);
|
voteThingListener.onVoteThingSuccess(position);
|
||||||
} else {
|
} else {
|
||||||
voteThingListener.onVoteThingFail(position);
|
voteThingListener.onVoteThingFail(position);
|
||||||
|
Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
voteThingListener.onVoteThingFail(position);
|
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 VoteThingWithoutPositionListener voteThingWithoutPositionListener,
|
||||||
final String fullName, final String point) {
|
final String fullName, final String point) {
|
||||||
RedditAPI api = retrofit.create(RedditAPI.class);
|
RedditAPI api = retrofit.create(RedditAPI.class);
|
||||||
@ -62,12 +67,14 @@ public class VoteThing {
|
|||||||
voteThingWithoutPositionListener.onVoteThingSuccess();
|
voteThingWithoutPositionListener.onVoteThingSuccess();
|
||||||
} else {
|
} else {
|
||||||
voteThingWithoutPositionListener.onVoteThingFail();
|
voteThingWithoutPositionListener.onVoteThingFail();
|
||||||
|
Toast.makeText(context, "Code " + response.code() + " Body: " + response.body(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||||
voteThingWithoutPositionListener.onVoteThingFail();
|
voteThingWithoutPositionListener.onVoteThingFail();
|
||||||
|
Toast.makeText(context, "Network error " + "Body: " + t.getMessage(), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user