diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-09-24 11:16:35 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-09-24 11:16:35 +0000 |
commit | cfab68ecd664649dec39e34116fc0a25c088b307 (patch) | |
tree | 75f625ace93f651549c74de2d135b429b40b1faa | |
parent | 20053881f1ebde6ac5910a39b61f807fd8099058 (diff) | |
download | infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar.gz infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar.bz2 infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar.lz infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar.xz infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.tar.zst infinity-for-reddit-cfab68ecd664649dec39e34116fc0a25c088b307.zip |
Favorite and unfavorite users for the anonymous user.
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java index 29aace70..81ae4fa3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FavoriteThing.java @@ -83,50 +83,60 @@ public class FavoriteThing { RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, SubscribedUserData subscribedUserData, FavoriteThingListener favoriteThingListener) { - Map<String, String> params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { - @Override - public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedUserData, favoriteThingListener::success); - } else { - favoriteThingListener.failed(); + if (accessToken == null) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + Map<String, String> params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "true"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } } - } - @Override - public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } } public static void unfavoriteUser(Executor executor, Handler handler, Retrofit oauthRetrofit, RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, SubscribedUserData subscribedUserData, FavoriteThingListener favoriteThingListener) { - Map<String, String> params = new HashMap<>(); - params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); - params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); - oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { - @Override - public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { - if (response.isSuccessful()) { - InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, - subscribedUserData, favoriteThingListener::success); - } else { - favoriteThingListener.failed(); + if (accessToken == null) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, subscribedUserData, + favoriteThingListener::success); + } else { + Map<String, String> params = new HashMap<>(); + params.put(APIUtils.SR_NAME_KEY, "u_" + subscribedUserData.getName()); + params.put(APIUtils.MAKE_FAVORITE_KEY, "false"); + oauthRetrofit.create(RedditAPI.class).favoriteThing(APIUtils.getOAuthHeader(accessToken), params).enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if (response.isSuccessful()) { + InsertSubscribedThings.insertSubscribedThings(executor, handler, redditDataRoomDatabase, + subscribedUserData, favoriteThingListener::success); + } else { + favoriteThingListener.failed(); + } } - } - @Override - public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { - favoriteThingListener.failed(); - } - }); + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + favoriteThingListener.failed(); + } + }); + } } public interface FavoriteThingListener { |