From c756342ce6423e973d7d426a76012123b6b2d501 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Sat, 22 Jul 2023 16:36:15 +0200 Subject: [PATCH] Fix bug with post detail refreshing Signed-off-by: Balazs Toldi --- .../java/eu/toldi/infinityforlemmy/apis/LemmyAPI.java | 7 +++++-- .../java/eu/toldi/infinityforlemmy/post/FetchPost.java | 10 ++++------ .../java/eu/toldi/infinityforlemmy/post/ParsePost.java | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/apis/LemmyAPI.java b/app/src/main/java/eu/toldi/infinityforlemmy/apis/LemmyAPI.java index 159fa5f4..22ff3be6 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/apis/LemmyAPI.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/apis/LemmyAPI.java @@ -19,10 +19,13 @@ public interface LemmyAPI { Call userLogin(@Body AccountLoginDTO params); @GET("api/v3/user") - Call userInfo(@Query("username") String username,@Query("auth") String access_token); + Call userInfo(@Query("username") String username, @Query("auth") String access_token); @GET("api/v3/community") - Call communityInfo(@Query("name") String name,@Query("auth") String access_token); + Call communityInfo(@Query("name") String name, @Query("auth") String access_token); + + @GET("api/v3/post") + Call postInfo(@Query("id") Integer postID, @Query("comment_id") Integer comment_id, @Query("auth") String access_token); @GET("api/v3/user") ListenableFuture> getUserPosts( diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/post/FetchPost.java b/app/src/main/java/eu/toldi/infinityforlemmy/post/FetchPost.java index 9b2eba42..dd449c07 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/post/FetchPost.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/post/FetchPost.java @@ -6,8 +6,8 @@ import androidx.annotation.NonNull; import java.util.concurrent.Executor; +import eu.toldi.infinityforlemmy.apis.LemmyAPI; import eu.toldi.infinityforlemmy.apis.RedditAPI; -import eu.toldi.infinityforlemmy.utils.APIUtils; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -17,11 +17,9 @@ public class FetchPost { public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken, FetchPostListener fetchPostListener) { Call postCall; - if (accessToken == null) { - postCall = retrofit.create(RedditAPI.class).getPost(id); - } else { - postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken)); - } + // Use LemmyAPI.postInfo() instead of RedditAPI.getPost() + postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken); + postCall.enqueue(new Callback<>() { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/post/ParsePost.java b/app/src/main/java/eu/toldi/infinityforlemmy/post/ParsePost.java index d5e48c5c..24221751 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/post/ParsePost.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/post/ParsePost.java @@ -98,13 +98,13 @@ public class ParsePost { executor.execute(() -> { try { - JSONArray allData = new JSONArray(response).getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY); + JSONObject allData = new JSONObject(response).getJSONObject("post_view"); if (allData.length() == 0) { handler.post(parsePostListener::onParsePostFail); return; } - JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY); - Post post = parseBasicData(data); + + Post post = parseBasicData(allData); handler.post(() -> parsePostListener.onParsePostSuccess(post)); } catch (JSONException e) { e.printStackTrace();