aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-22 02:47:30 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-08-22 02:47:30 +0000
commitd270378ecdecd2760ec237d09a0e0b3470001325 (patch)
treedacbe6aa37a4b559612bdd3033d9efc2c8be0fa5 /app/src/main/java/ml/docilealligator
parent7b9ece76fd7a5daf68a43b3aa05946e4d374ad5e (diff)
downloadinfinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar.gz
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar.bz2
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar.lz
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar.xz
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.tar.zst
infinity-for-reddit-d270378ecdecd2760ec237d09a0e0b3470001325.zip
Searching posts inside a multireddit is available.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java67
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java80
5 files changed, 163 insertions, 30 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
index 059bea5a..331d59ff 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java
@@ -804,8 +804,19 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private Fragment createPostFragment() {
PostFragment mFragment = new PostFragment();
Bundle bundle = new Bundle();
- bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
- bundle.putString(PostFragment.EXTRA_NAME, mSearchInThingType == SelectThingReturnKey.THING_TYPE.USER ? "u_" + mSearchInSubredditOrUserName : mSearchInSubredditOrUserName);
+ switch (mSearchInThingType) {
+ case SelectThingReturnKey.THING_TYPE.SUBREDDIT:
+ bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
+ bundle.putString(PostFragment.EXTRA_NAME, mSearchInSubredditOrUserName);
+ break;
+ case SelectThingReturnKey.THING_TYPE.USER:
+ bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
+ bundle.putString(PostFragment.EXTRA_NAME, "u_" + mSearchInSubredditOrUserName);
+ break;
+ case SelectThingReturnKey.THING_TYPE.MULTIREDDIT:
+ bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_MULTI_REDDIT);
+ bundle.putString(PostFragment.EXTRA_NAME, mSearchInMultiReddit.getPath());
+ }
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
mFragment.setArguments(bundle);
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 78bb8bb4..fdf89e9a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -320,12 +320,27 @@ public interface RedditAPI {
@GET("{multipath}?raw_json=1&limit=100")
ListenableFuture<Response<String>> getMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
+ @Path(value = "sortType", encoded = true) SortType.Type sortType,
@Query("after") String after, @Query("t") SortType.Time sortTime);
- @GET("{multipath}.json?raw_json=1&limit=100")
+ @GET("{multipath}/{sortType}.json?raw_json=1&limit=100")
ListenableFuture<Response<String>> getMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath,
- @Query("after") String after, @Query("t") SortType.Time sortTime,
- @HeaderMap Map<String, String> headers);
+ @Path(value = "sortType", encoded = true) SortType.Type sortType,
+ @Query("after") String after, @Query("t") SortType.Time sortTime,
+ @HeaderMap Map<String, String> headers);
+
+ @GET("{multipath}/search.json?raw_json=1&limit=100&type=link&restrict_sr=on&sr_detail=true&include_over_18=1&always_show_media=1")
+ ListenableFuture<Response<String>> searchMultiRedditPostsListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, @Query("q") String query,
+ @Query("after") String after,
+ @Query("sort") SortType.Type sortType,
+ @Query("t") SortType.Time sortTime);
+
+ @GET("{multipath}/search.json?raw_json=1&limit=100&type=link&restrict_sr=on&sr_detail=true&include_over_18=1&always_show_media=1")
+ ListenableFuture<Response<String>> searchMultiRedditPostsOauthListenableFuture(@Path(value = "multipath", encoded = true) String multiPath, @Query("q") String query,
+ @Query("after") String after,
+ @Query("sort") SortType.Type sortType,
+ @Query("t") SortType.Time sortTime,
+ @HeaderMap Map<String, String> headers);
@GET("{sortType}?raw_json=1&limit=100")
Call<String> getBestPosts(@Path("sortType") SortType.Type sortType, @Query("t") SortType.Time sortTime,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 2e488ac2..e4850443 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -558,8 +558,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
});
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
multiRedditPath = getArguments().getString(EXTRA_NAME);
+ query = getArguments().getString(EXTRA_QUERY);
if (savedInstanceState == null) {
- postFragmentId += multiRedditPath.hashCode();
+ postFragmentId += multiRedditPath.hashCode() + (query == null ? 0 : query.hashCode());
}
usage = PostFilterUsage.MULTIREDDIT_TYPE;
@@ -592,6 +593,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void typeChipClicked(int filter) {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
+ intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE_FILTER, filter);
startActivity(intent);
@@ -601,6 +603,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void flairChipClicked(String flair) {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
+ intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair);
startActivity(intent);
@@ -610,6 +613,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void nsfwChipClicked() {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
+ intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE_FILTER, Post.NSFW_TYPE);
startActivity(intent);
@@ -1190,7 +1194,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
activity.accountName.equals(Account.ANONYMOUS_ACCOUNT) ? mRetrofit : mOauthRetrofit, activity.accessToken, activity.accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
- mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
+ mPostHistorySharedPreferences, multiRedditPath, query, postType, sortType, postFilter, readPosts))
.get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
@@ -1208,7 +1212,6 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
private void initializeAndBindPostViewModelForAnonymous(String concatenatedSubredditNames) {
- //For anonymous user
if (postType == PostPagingSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit, null, activity.accountName, mSharedPreferences,
@@ -1669,6 +1672,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT || postType == PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT) {
Intent intent = new Intent(activity, CustomizePostFilterActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
+ intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
intent.putExtra(CustomizePostFilterActivity.EXTRA_START_FILTERED_POSTS_WHEN_FINISH, true);
startActivity(intent);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
index 7b0930ec..72038fba 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostPagingSource.java
@@ -76,9 +76,10 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
postLinkedHashSet = new LinkedHashSet<>();
}
+ // PostPagingSource.TYPE_SUBREDDIT || PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE || PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
PostPagingSource(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String path, int postType, SortType sortType, PostFilter postFilter,
+ String name, int postType, SortType sortType, PostFilter postFilter,
List<String> readPostList) {
this.executor = executor;
this.retrofit = retrofit;
@@ -86,25 +87,13 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
this.accountName = accountName;
this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
- if (postType == TYPE_SUBREDDIT || postType == TYPE_ANONYMOUS_FRONT_PAGE || postType == TYPE_ANONYMOUS_MULTIREDDIT) {
- this.subredditOrUserName = path;
- if (subredditOrUserName == null) {
- subredditOrUserName = "popular";
- }
- } else {
- if (sortType != null) {
- if (path.endsWith("/")) {
- multiRedditPath = path + sortType.getType().value;
- } else {
- multiRedditPath = path + "/" + sortType.getType().value;
- }
- } else {
- multiRedditPath = path;
- }
+ this.subredditOrUserName = name;
+ if (subredditOrUserName == null) {
+ subredditOrUserName = "popular";
}
this.postType = postType;
if (sortType == null) {
- if ("popular".equals(path) || "all".equals(path)) {
+ if ("popular".equals(name) || "all".equals(name)) {
this.sortType = new SortType(SortType.Type.HOT);
} else {
this.sortType = new SortType(SortType.Type.BEST);
@@ -117,6 +106,34 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
postLinkedHashSet = new LinkedHashSet<>();
}
+ // PostPagingSource.TYPE_MULTI_REDDIT
+ PostPagingSource(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
+ SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
+ String path, String query, int postType, SortType sortType, PostFilter postFilter,
+ List<String> readPostList) {
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ if (path.endsWith("/")) {
+ multiRedditPath = path.substring(0, multiRedditPath.length() - 1);
+ } else {
+ multiRedditPath = path;
+ }
+ this.query = query;
+ this.postType = postType;
+ if (sortType == null) {
+ this.sortType = new SortType(SortType.Type.HOT);
+ } else {
+ this.sortType = sortType;
+ }
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ postLinkedHashSet = new LinkedHashSet<>();
+ }
+
PostPagingSource(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
@@ -308,10 +325,20 @@ public class PostPagingSource extends ListenableFuturePagingSource<String, Post>
private ListenableFuture<LoadResult<String, Post>> loadMultiRedditPosts(@NonNull LoadParams<String> loadParams, RedditAPI api) {
ListenableFuture<Response<String>> multiRedditPosts;
if (accountName.equals(Account.ANONYMOUS_ACCOUNT)) {
- multiRedditPosts = api.getMultiRedditPostsListenableFuture(multiRedditPath, loadParams.getKey(), sortType.getTime());
+ if (query != null && !query.isEmpty()) {
+ multiRedditPosts = api.searchMultiRedditPostsListenableFuture(multiRedditPath, query, loadParams.getKey(),
+ sortType.getType(), sortType.getTime());
+ } else {
+ multiRedditPosts = api.getMultiRedditPostsListenableFuture(multiRedditPath, sortType.getType(), loadParams.getKey(), sortType.getTime());
+ }
} else {
- multiRedditPosts = api.getMultiRedditPostsOauthListenableFuture(multiRedditPath, loadParams.getKey(),
- sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
+ if (query != null && !query.isEmpty()) {
+ multiRedditPosts = api.searchMultiRedditPostsOauthListenableFuture(multiRedditPath, query, loadParams.getKey(),
+ sortType.getType(), sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
+ } else {
+ multiRedditPosts = api.getMultiRedditPostsOauthListenableFuture(multiRedditPath, sortType.getType(), loadParams.getKey(),
+ sortType.getTime(), APIUtils.getOAuthHeader(accessToken));
+ }
}
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(multiRedditPosts, this::transformData, executor);
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 aad51bad..c3ea8734 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
@@ -51,6 +51,7 @@ public class PostViewModel extends ViewModel {
private final MutableLiveData<PostFilter> postFilterLiveData;
private final SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
+ // PostPagingSource.TYPE_FRONT_PAGE
public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
@@ -90,6 +91,7 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
+ // PostPagingSource.TYPE_SUBREDDIT || PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE || PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT
public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
@@ -130,6 +132,48 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
+ // PostPagingSource.TYPE_MULTI_REDDIT
+ public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
+ SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
+ @Nullable SharedPreferences postHistorySharedPreferences, String multiredditPath, String query, int postType,
+ SortType sortType, PostFilter postFilter, List<String> readPostList) {
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ this.name = multiredditPath;
+ this.query = query;
+
+ sortTypeLiveData = new MutableLiveData<>(sortType);
+ postFilterLiveData = new MutableLiveData<>(postFilter);
+
+ sortTypeAndPostFilterLiveData = new SortTypeAndPostFilterLiveData(sortTypeLiveData, postFilterLiveData);
+
+ Pager<String, Post> pager = new Pager<>(new PagingConfig(100, 4, false, 10), this::returnPagingSoruce);
+
+ posts = Transformations.switchMap(sortTypeAndPostFilterLiveData, sortAndPostFilter -> {
+ changeSortTypeAndPostFilter(
+ sortTypeLiveData.getValue(), postFilterLiveData.getValue());
+ return PagingLiveData.cachedIn(PagingLiveData.getLiveData(pager), ViewModelKt.getViewModelScope(this));
+ });
+
+ postsWithReadPostsHidden = PagingLiveData.cachedIn(Transformations.switchMap(currentlyReadPostIdsLiveData,
+ currentlyReadPostIds -> Transformations.map(
+ posts,
+ postPagingData -> PagingDataTransforms.filter(
+ postPagingData, executor,
+ post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
+
+ currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
+ && postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
+ }
+
public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences,
@@ -173,6 +217,7 @@ public class PostViewModel extends ViewModel {
&& postHistorySharedPreferences.getBoolean((accountName.equals(Account.ANONYMOUS_ACCOUNT) ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
}
+ // postType == PostPagingSource.TYPE_SEARCH
public PostViewModel(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
@@ -233,13 +278,17 @@ public class PostViewModel extends ViewModel {
postFilter, readPostList);
break;
case PostPagingSource.TYPE_SUBREDDIT:
- case PostPagingSource.TYPE_MULTI_REDDIT:
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, postType,
sortType, postFilter, readPostList);
break;
+ case PostPagingSource.TYPE_MULTI_REDDIT:
+ paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, postType,
+ sortType, postFilter, readPostList);
+ break;
case PostPagingSource.TYPE_SEARCH:
paging3PagingSource = new PostPagingSource(executor, retrofit, accessToken, accountName,
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
@@ -285,6 +334,7 @@ public class PostViewModel extends ViewModel {
private String userWhere;
private List<String> readPostList;
+ // Front page
public Factory(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
@@ -302,6 +352,7 @@ public class PostViewModel extends ViewModel {
this.readPostList = readPostList;
}
+ // PostPagingSource.TYPE_SUBREDDIT
public Factory(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
@@ -320,6 +371,26 @@ public class PostViewModel extends ViewModel {
this.readPostList = readPostList;
}
+ // PostPagingSource.TYPE_MULTI_REDDIT
+ public Factory(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
+ SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
+ SharedPreferences postHistorySharedPreferences, String name, String query, int postType, SortType sortType,
+ PostFilter postFilter, List<String> readPostList) {
+ this.executor = executor;
+ this.retrofit = retrofit;
+ this.accessToken = accessToken;
+ this.accountName = accountName;
+ this.sharedPreferences = sharedPreferences;
+ this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postHistorySharedPreferences = postHistorySharedPreferences;
+ this.name = name;
+ this.query = query;
+ this.postType = postType;
+ this.sortType = sortType;
+ this.postFilter = postFilter;
+ this.readPostList = readPostList;
+ }
+
//User posts
public Factory(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@@ -340,6 +411,7 @@ public class PostViewModel extends ViewModel {
this.readPostList = readPostList;
}
+ // PostPagingSource.TYPE_SEARCH
public Factory(Executor executor, Retrofit retrofit, @Nullable String accessToken, @NonNull String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
@@ -383,10 +455,14 @@ public class PostViewModel extends ViewModel {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
trendingSource, postType, sortType, postFilter, readPostList);
- } else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
+ } else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
postType, sortType, postFilter, readPostList);
+ } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
+ return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
+ postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
+ postType, sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE || postType == PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT) {
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
null, null, name, postType, sortType,