From cdd25f3405b7a41e796507612e83b394a1479d64 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 17 Dec 2019 18:54:14 +0800 Subject: Fixed sort type cannot be changed for multireddit. --- .../infinityforreddit/PostDataSource.java | 23 ++++++++++++---------- .../infinityforreddit/RedditAPI.java | 16 +++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java index 058dbc98..fc207a02 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSource.java @@ -68,7 +68,11 @@ public class PostDataSource extends PageKeyedDataSource { if (postType == TYPE_SUBREDDIT) { this.subredditOrUserName = path; } else { - multiRedditPath = path; + if (path.endsWith("/")) { + multiRedditPath = path + sortType.getType().value; + } else { + multiRedditPath = path + "/" + sortType.getType().value; + } } paginationNetworkStateLiveData = new MutableLiveData<>(); initialLoadStateLiveData = new MutableLiveData<>(); @@ -747,17 +751,16 @@ public class PostDataSource extends PageKeyedDataSource { Call getPost; if (accessToken == null) { if (sortType.getTime() != null) { - getPost = api.getMultiRedditPosts(multiRedditPath, lastItem, sortType.getType().value, - sortType.getTime().value); + getPost = api.getMultiRedditPosts(multiRedditPath, lastItem, sortType.getTime().value); } else { - getPost = api.getMultiRedditPosts(multiRedditPath, lastItem, sortType.getType().value); + getPost = api.getMultiRedditPosts(multiRedditPath, lastItem); } } else { if (sortType.getTime() != null) { - getPost = api.getMultiRedditPostsOauth(multiRedditPath, lastItem, sortType.getType().value, + getPost = api.getMultiRedditPostsOauth(multiRedditPath, lastItem, sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken)); } else { - getPost = api.getMultiRedditPostsOauth(multiRedditPath, lastItem, sortType.getType().value, + getPost = api.getMultiRedditPostsOauth(multiRedditPath, lastItem, RedditUtils.getOAuthHeader(accessToken)); } } @@ -817,17 +820,17 @@ public class PostDataSource extends PageKeyedDataSource { Call getPost; if (accessToken == null) { if (sortType.getTime() != null) { - getPost = api.getMultiRedditPosts(multiRedditPath, after, sortType.getType().value, + getPost = api.getMultiRedditPosts(multiRedditPath, after, sortType.getTime().value); } else { - getPost = api.getMultiRedditPosts(multiRedditPath, after, sortType.getType().value); + getPost = api.getMultiRedditPosts(multiRedditPath, after); } } else { if (sortType.getTime() != null) { - getPost = api.getMultiRedditPostsOauth(multiRedditPath, after, sortType.getType().value, + getPost = api.getMultiRedditPostsOauth(multiRedditPath, after, sortType.getTime().value, RedditUtils.getOAuthHeader(accessToken)); } else { - getPost = api.getMultiRedditPostsOauth(multiRedditPath, after, sortType.getType().value, + getPost = api.getMultiRedditPostsOauth(multiRedditPath, after, RedditUtils.getOAuthHeader(accessToken)); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index 73b1df87..848e8807 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -273,19 +273,19 @@ public interface RedditAPI { Call getUserMultiReddits(@Path("username") String username); @GET("{multipath}?raw_json=1") - Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, - @Query("sort") String sortType); + Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, + @Query("after") String after); @GET("{multipath}?raw_json=1") - Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, - @Query("sort") String sortType, @Query("t") String sortTime); + Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, + @Query("after") String after, @Query("t") String sortTime); @GET("{multipath}.json?raw_json=1") - Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, - @Query("sort") String sortType, @Query("t") String sortTime, + Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, + @Query("after") String after, @Query("t") String sortTime, @HeaderMap Map headers); @GET("{multipath}.json?raw_json=1") - Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, - @Query("sort") String sortType, @HeaderMap Map headers); + Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, + @Query("after") String after, @HeaderMap Map headers); } -- cgit v1.2.3