@@ -76,35 +76,24 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
76
76
postLinkedHashSet = new LinkedHashSet <>();
77
77
}
78
78
79
+ // PostPagingSource.TYPE_SUBREDDIT || PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE || PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
79
80
PostPagingSource (Executor executor , Retrofit retrofit , @ Nullable String accessToken , @ NonNull String accountName ,
80
81
SharedPreferences sharedPreferences , SharedPreferences postFeedScrolledPositionSharedPreferences ,
81
- String path , int postType , SortType sortType , PostFilter postFilter ,
82
+ String name , int postType , SortType sortType , PostFilter postFilter ,
82
83
List <String > readPostList ) {
83
84
this .executor = executor ;
84
85
this .retrofit = retrofit ;
85
86
this .accessToken = accessToken ;
86
87
this .accountName = accountName ;
87
88
this .sharedPreferences = sharedPreferences ;
88
89
this .postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences ;
89
- if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE || postType == TYPE_ANONYMOUS_MULTIREDDIT ) {
90
- this .subredditOrUserName = path ;
91
- if (subredditOrUserName == null ) {
92
- subredditOrUserName = "popular" ;
93
- }
94
- } else {
95
- if (sortType != null ) {
96
- if (path .endsWith ("/" )) {
97
- multiRedditPath = path + sortType .getType ().value ;
98
- } else {
99
- multiRedditPath = path + "/" + sortType .getType ().value ;
100
- }
101
- } else {
102
- multiRedditPath = path ;
103
- }
90
+ this .subredditOrUserName = name ;
91
+ if (subredditOrUserName == null ) {
92
+ subredditOrUserName = "popular" ;
104
93
}
105
94
this .postType = postType ;
106
95
if (sortType == null ) {
107
- if ("popular" .equals (path ) || "all" .equals (path )) {
96
+ if ("popular" .equals (name ) || "all" .equals (name )) {
108
97
this .sortType = new SortType (SortType .Type .HOT );
109
98
} else {
110
99
this .sortType = new SortType (SortType .Type .BEST );
@@ -117,6 +106,34 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
117
106
postLinkedHashSet = new LinkedHashSet <>();
118
107
}
119
108
109
+ // PostPagingSource.TYPE_MULTI_REDDIT
110
+ PostPagingSource (Executor executor , Retrofit retrofit , @ Nullable String accessToken , @ NonNull String accountName ,
111
+ SharedPreferences sharedPreferences , SharedPreferences postFeedScrolledPositionSharedPreferences ,
112
+ String path , String query , int postType , SortType sortType , PostFilter postFilter ,
113
+ List <String > readPostList ) {
114
+ this .executor = executor ;
115
+ this .retrofit = retrofit ;
116
+ this .accessToken = accessToken ;
117
+ this .accountName = accountName ;
118
+ this .sharedPreferences = sharedPreferences ;
119
+ this .postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences ;
120
+ if (path .endsWith ("/" )) {
121
+ multiRedditPath = path .substring (0 , multiRedditPath .length () - 1 );
122
+ } else {
123
+ multiRedditPath = path ;
124
+ }
125
+ this .query = query ;
126
+ this .postType = postType ;
127
+ if (sortType == null ) {
128
+ this .sortType = new SortType (SortType .Type .HOT );
129
+ } else {
130
+ this .sortType = sortType ;
131
+ }
132
+ this .postFilter = postFilter ;
133
+ this .readPostList = readPostList ;
134
+ postLinkedHashSet = new LinkedHashSet <>();
135
+ }
136
+
120
137
PostPagingSource (Executor executor , Retrofit retrofit , @ Nullable String accessToken , @ NonNull String accountName ,
121
138
SharedPreferences sharedPreferences , SharedPreferences postFeedScrolledPositionSharedPreferences ,
122
139
String subredditOrUserName , int postType , SortType sortType , PostFilter postFilter ,
@@ -308,10 +325,20 @@ private ListenableFuture<LoadResult<String, Post>> loadSearchPosts(@NonNull Load
308
325
private ListenableFuture <LoadResult <String , Post >> loadMultiRedditPosts (@ NonNull LoadParams <String > loadParams , RedditAPI api ) {
309
326
ListenableFuture <Response <String >> multiRedditPosts ;
310
327
if (accountName .equals (Account .ANONYMOUS_ACCOUNT )) {
311
- multiRedditPosts = api .getMultiRedditPostsListenableFuture (multiRedditPath , loadParams .getKey (), sortType .getTime ());
328
+ if (query != null && !query .isEmpty ()) {
329
+ multiRedditPosts = api .searchMultiRedditPostsListenableFuture (multiRedditPath , query , loadParams .getKey (),
330
+ sortType .getType (), sortType .getTime ());
331
+ } else {
332
+ multiRedditPosts = api .getMultiRedditPostsListenableFuture (multiRedditPath , sortType .getType (), loadParams .getKey (), sortType .getTime ());
333
+ }
312
334
} else {
313
- multiRedditPosts = api .getMultiRedditPostsOauthListenableFuture (multiRedditPath , loadParams .getKey (),
314
- sortType .getTime (), APIUtils .getOAuthHeader (accessToken ));
335
+ if (query != null && !query .isEmpty ()) {
336
+ multiRedditPosts = api .searchMultiRedditPostsOauthListenableFuture (multiRedditPath , query , loadParams .getKey (),
337
+ sortType .getType (), sortType .getTime (), APIUtils .getOAuthHeader (accessToken ));
338
+ } else {
339
+ multiRedditPosts = api .getMultiRedditPostsOauthListenableFuture (multiRedditPath , sortType .getType (), loadParams .getKey (),
340
+ sortType .getTime (), APIUtils .getOAuthHeader (accessToken ));
341
+ }
315
342
}
316
343
317
344
ListenableFuture <LoadResult <String , Post >> pageFuture = Futures .transform (multiRedditPosts , this ::transformData , executor );
0 commit comments