mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 03:18:24 +01:00
Fix bug with post detail refreshing
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
258ff290bb
commit
c756342ce6
@ -24,6 +24,9 @@ public interface LemmyAPI {
|
|||||||
@GET("api/v3/community")
|
@GET("api/v3/community")
|
||||||
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
|
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
|
||||||
|
|
||||||
|
@GET("api/v3/post")
|
||||||
|
Call<String> postInfo(@Query("id") Integer postID, @Query("comment_id") Integer comment_id, @Query("auth") String access_token);
|
||||||
|
|
||||||
@GET("api/v3/user")
|
@GET("api/v3/user")
|
||||||
ListenableFuture<Response<String>> getUserPosts(
|
ListenableFuture<Response<String>> getUserPosts(
|
||||||
@Query("username") String username,
|
@Query("username") String username,
|
||||||
|
@ -6,8 +6,8 @@ import androidx.annotation.NonNull;
|
|||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
@ -17,11 +17,9 @@ public class FetchPost {
|
|||||||
public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
|
public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
|
||||||
FetchPostListener fetchPostListener) {
|
FetchPostListener fetchPostListener) {
|
||||||
Call<String> postCall;
|
Call<String> postCall;
|
||||||
if (accessToken == null) {
|
// Use LemmyAPI.postInfo() instead of RedditAPI.getPost()
|
||||||
postCall = retrofit.create(RedditAPI.class).getPost(id);
|
postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken);
|
||||||
} else {
|
|
||||||
postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken));
|
|
||||||
}
|
|
||||||
postCall.enqueue(new Callback<>() {
|
postCall.enqueue(new Callback<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
|
@ -98,13 +98,13 @@ public class ParsePost {
|
|||||||
|
|
||||||
executor.execute(() -> {
|
executor.execute(() -> {
|
||||||
try {
|
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) {
|
if (allData.length() == 0) {
|
||||||
handler.post(parsePostListener::onParsePostFail);
|
handler.post(parsePostListener::onParsePostFail);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY);
|
|
||||||
Post post = parseBasicData(data);
|
Post post = parseBasicData(allData);
|
||||||
handler.post(() -> parsePostListener.onParsePostSuccess(post));
|
handler.post(() -> parsePostListener.onParsePostSuccess(post));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
Reference in New Issue
Block a user