mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 12:47:26 +01:00
Favorite and unfavorite users for the anonymous user.
This commit is contained in:
parent
20053881f1
commit
cfab68ecd6
@ -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 {
|
||||
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 {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user