From de4eab7e9c29407488ae00037ddb1b84e5a38290 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:29:11 -0400 Subject: Load more items in a single call. --- .../infinityforreddit/apis/RedditAPI.java | 52 +++++++++++----------- .../comment/CommentViewModel.java | 4 +- .../infinityforreddit/post/PostViewModel.java | 8 ++-- 3 files changed, 33 insertions(+), 31 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java index 41d44d38..a85d5078 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java @@ -54,19 +54,19 @@ public interface RedditAPI { @GET("user/{username}/about.json?raw_json=1") Call getUserData(@Path("username") String username); - @GET("user/{username}/about.json?raw_json=1") + @GET("user/{username}/about.json?raw_json=1&limit=100") Call getUserDataOauth(@HeaderMap Map headers, @Path("username") String username); - @GET("user/{username}/comments.json?raw_json=1") + @GET("user/{username}/comments.json?raw_json=1&limit=100") Call getUserComments(@Path("username") String username, @Query("after") String after, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("user/{username}/comments.json?raw_json=1") + @GET("user/{username}/comments.json?raw_json=1&limit=100") Call getUserCommentsOauth(@HeaderMap Map headers, @Path("username") String username, @Query("after") String after, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=25") + @GET("user/{username}/{where}.json?&type=comments&raw_json=1&limit=100") Call getUserSavedCommentsOauth(@Path("username") String username, @Path("where") String where, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); @@ -273,108 +273,108 @@ public interface RedditAPI { @GET("/r/{subredditName}/wiki/{wikiPage}.json?raw_json=1") Call getWikiPage(@Path("subredditName") String subredditName, @Path("wikiPage") String wikiPage); - @GET("{sortType}?raw_json=1") + @GET("{sortType}?raw_json=1&limit=100") ListenableFuture> getBestPostsListenableFuture(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") + @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") ListenableFuture> getSubredditBestPostsOauthListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") + @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") ListenableFuture> getSubredditBestPostsListenableFuture(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem); - @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25") + @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100") ListenableFuture> getUserPostsOauthListenableFuture(@Path("username") String username, @Path("where") String where, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); - @GET("user/{username}/submitted.json?raw_json=1&limit=25") + @GET("user/{username}/submitted.json?raw_json=1&limit=100") ListenableFuture> getUserPostsListenableFuture(@Path("username") String username, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("search.json?include_over_18=1&raw_json=1&type=link") + @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") ListenableFuture> searchPostsOauthListenableFuture(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source, @HeaderMap Map headers); - @GET("search.json?include_over_18=1&raw_json=1&type=link") + @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") ListenableFuture> searchPostsListenableFuture(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") + @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") ListenableFuture> searchPostsInSpecificSubredditOauthListenableFuture(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after, @HeaderMap Map headers); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") + @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") ListenableFuture> searchPostsInSpecificSubredditListenableFuture(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after); - @GET("{multipath}?raw_json=1") + @GET("{multipath}?raw_json=1&limit=100") ListenableFuture> getMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime); - @GET("{multipath}.json?raw_json=1") + @GET("{multipath}.json?raw_json=1&limit=100") ListenableFuture> getMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); - @GET("{sortType}?raw_json=1") + @GET("{sortType}?raw_json=1&limit=100") Call getBestPosts(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") + @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") Call getSubredditBestPostsOauth(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem, @HeaderMap Map headers); - @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=25&always_show_media=1") + @GET("r/{subredditName}/{sortType}.json?raw_json=1&limit=100&always_show_media=1") Call getSubredditBestPosts(@Path("subredditName") String subredditName, @Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime, @Query("after") String lastItem); - @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=25") + @GET("user/{username}/{where}.json?&type=links&raw_json=1&limit=100") Call getUserPostsOauth(@Path("username") String username, @Path("where") String where, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); - @GET("user/{username}/submitted.json?raw_json=1&limit=25") + @GET("user/{username}/submitted.json?raw_json=1&limit=100") Call getUserPosts(@Path("username") String username, @Query("after") String lastItem, @Query("sort") SortType.Type sortType, @Query("t") SortType.Time sortTime); - @GET("search.json?include_over_18=1&raw_json=1&type=link") + @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") Call searchPostsOauth(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source, @HeaderMap Map headers); - @GET("search.json?include_over_18=1&raw_json=1&type=link") + @GET("search.json?include_over_18=1&raw_json=1&limit=100&type=link") Call searchPosts(@Query("q") String query, @Query("after") String after, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("source") String source); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") + @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") Call searchPostsInSpecificSubredditOauth(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after, @HeaderMap Map headers); - @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&type=link&restrict_sr=true") + @GET("r/{subredditName}/search.json?include_over_18=1&raw_json=1&limit=100&type=link&restrict_sr=true") Call searchPostsInSpecificSubreddit(@Path("subredditName") String subredditName, @Query("q") String query, @Query("sort") SortType.Type sort, @Query("t") SortType.Time sortTime, @Query("after") String after); - @GET("{multipath}?raw_json=1") + @GET("{multipath}?raw_json=1&limit=100") Call getMultiRedditPosts(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime); - @GET("{multipath}.json?raw_json=1") + @GET("{multipath}.json?raw_json=1&limit=100") Call getMultiRedditPostsOauth(@Path(value = "multipath", encoded = true) String multiPath, @Query("after") String after, @Query("t") SortType.Time sortTime, @HeaderMap Map headers); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java index de9f246b..e6ccd0ca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/comment/CommentViewModel.java @@ -40,7 +40,9 @@ public class CommentViewModel extends ViewModel { PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) .setEnablePlaceholders(false) - .setPageSize(25) + .setPageSize(100) + .setPrefetchDistance(10) + .setInitialLoadSizeHint(10) .build(); comments = Transformations.switchMap(sortTypeLiveData, sort -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java index b1d32cf6..acb13de1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java @@ -70,7 +70,7 @@ public class PostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - Pager pager = new Pager<>(new PagingConfig(25, 4, false, 1), this::returnPagingSoruce); + Pager pager = new Pager<>(new PagingConfig(100, 4, false, 10), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { changeSortTypeAndPostFilter( @@ -110,7 +110,7 @@ public class PostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - Pager pager = new Pager<>(new PagingConfig(25, 4, false, 1), this::returnPagingSoruce); + Pager pager = new Pager<>(new PagingConfig(100, 4, false, 10), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { changeSortTypeAndPostFilter( @@ -153,7 +153,7 @@ public class PostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - Pager pager = new Pager<>(new PagingConfig(25, 4, false, 1), this::returnPagingSoruce); + Pager pager = new Pager<>(new PagingConfig(100, 4, false, 10), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { changeSortTypeAndPostFilter( @@ -196,7 +196,7 @@ public class PostViewModel extends ViewModel { sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData); - Pager pager = new Pager<>(new PagingConfig(25, 4, false, 1), this::returnPagingSoruce); + Pager pager = new Pager<>(new PagingConfig(100, 4, false, 10), this::returnPagingSoruce); posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> { changeSortTypeAndPostFilter( -- cgit v1.2.3