Fix hiding read posts automatically.

This commit is contained in:
Alex Ning 2021-09-17 21:06:53 +08:00
parent 5dda05d7fa
commit 474b3cf32f
3 changed files with 65 additions and 58 deletions

View File

@ -194,7 +194,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private boolean mMarkPostsAsRead; private boolean mMarkPostsAsRead;
private boolean mMarkPostsAsReadAfterVoting; private boolean mMarkPostsAsReadAfterVoting;
private boolean mMarkPostsAsReadOnScroll; private boolean mMarkPostsAsReadOnScroll;
private boolean mHideReadPostsAutomatically;
private boolean mHidePostType; private boolean mHidePostType;
private boolean mHidePostFlair; private boolean mHidePostFlair;
private boolean mHideTheNumberOfAwards; private boolean mHideTheNumberOfAwards;
@ -268,7 +267,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false); mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false); mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false);
mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false); mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false);
mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false);
mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false); mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false); mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);

View File

@ -49,18 +49,15 @@ import androidx.transition.TransitionManager;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager; import com.bumptech.glide.RequestManager;
import com.google.common.collect.Lists;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
@ -1082,31 +1079,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences, accountName, mSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource, mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class); query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) { } else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
postFilter, readPosts)).get(PostViewModel.class); .get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) { } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
postFilter, readPosts)).get(PostViewModel.class); .get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) { } else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken, accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter, mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
where, readPosts)).get(PostViewModel.class); .get(PostViewModel.class);
} else { } else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mOauthRetrofit, accessToken, mOauthRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class); mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} }
bindPostViewModel(); bindPostViewModel();
@ -1116,33 +1113,29 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
//For anonymous user //For anonymous user
if (postType == PostPagingSource.TYPE_SEARCH) { if (postType == PostPagingSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit, null, mRetrofit, null, accountName, mSharedPreferences,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class); postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) { } else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
mRetrofit, null, mRetrofit, null, accountName, mSharedPreferences,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
postFilter, readPosts)).get(PostViewModel.class); postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) { } else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit, null, mRetrofit, null, accountName, mSharedPreferences,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) { } else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit, null, mRetrofit, null, accountName, mSharedPreferences,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
where, readPosts)).get(PostViewModel.class); where, readPosts)).get(PostViewModel.class);
} else { } else {
//Anonymous Front Page //Anonymous Front Page
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor, mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mRetrofit, mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter))
mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)).get(PostViewModel.class); .get(PostViewModel.class);
} }
bindPostViewModel(); bindPostViewModel();

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.post;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair; import androidx.core.util.Pair;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData; import androidx.lifecycle.MediatorLiveData;
@ -18,12 +19,12 @@ import androidx.paging.PagingDataTransforms;
import androidx.paging.PagingLiveData; import androidx.paging.PagingLiveData;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter; import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
import ml.docilealligator.infinityforreddit.readpost.ReadPost; import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class PostViewModel extends ViewModel { public class PostViewModel extends ViewModel {
@ -51,7 +52,8 @@ public class PostViewModel extends ViewModel {
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData; private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, int postType,
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) { SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
@ -86,13 +88,14 @@ public class PostViewModel extends ViewModel {
postPagingData, executor, postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(false); currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
} }
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String subredditName, int postType, SortType sortType, PostFilter postFilter, @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
List<ReadPost> readPostList) { SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
@ -127,12 +130,14 @@ public class PostViewModel extends ViewModel {
postPagingData, executor, postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(false); currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
} }
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences, String username, SharedPreferences postFeedScrolledPositionSharedPreferences,
@Nullable SharedPreferences postHistorySharedPreferences, String username,
int postType, SortType sortType, PostFilter postFilter, String userWhere, int postType, SortType sortType, PostFilter postFilter, String userWhere,
List<ReadPost> readPostList) { List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
@ -170,13 +175,15 @@ public class PostViewModel extends ViewModel {
postPagingData, executor, postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(false); currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
} }
public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName, public PostViewModel(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String subredditName, String query, String trendingSource, int postType, SortType sortType, @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
PostFilter postFilter, List<ReadPost> readPostList) { String trendingSource, int postType, SortType sortType, PostFilter postFilter,
List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
@ -213,7 +220,8 @@ public class PostViewModel extends ViewModel {
postPagingData, executor, postPagingData, executor,
post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this)); post -> !post.isRead() || !currentlyReadPostIdsLiveData.getValue()))), ViewModelKt.getViewModelScope(this));
currentlyReadPostIdsLiveData.setValue(false); currentlyReadPostIdsLiveData.setValue(postHistorySharedPreferences != null
&& postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
} }
public LiveData<PagingData<Post>> getPosts() { public LiveData<PagingData<Post>> getPosts() {
@ -274,6 +282,7 @@ public class PostViewModel extends ViewModel {
private String accountName; private String accountName;
private SharedPreferences sharedPreferences; private SharedPreferences sharedPreferences;
private SharedPreferences postFeedScrolledPositionSharedPreferences; private SharedPreferences postFeedScrolledPositionSharedPreferences;
private SharedPreferences postHistorySharedPreferences;
private String name; private String name;
private String query; private String query;
private String trendingSource; private String trendingSource;
@ -285,13 +294,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName, public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) { SharedPreferences postHistorySharedPreferences, int postType, SortType sortType,
PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
this.accountName = accountName; this.accountName = accountName;
this.sharedPreferences = sharedPreferences; this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences; this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.postHistorySharedPreferences = postHistorySharedPreferences;
this.postType = postType; this.postType = postType;
this.sortType = sortType; this.sortType = sortType;
this.postFilter = postFilter; this.postFilter = postFilter;
@ -300,13 +311,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName, public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String name, int postType, SortType sortType, PostFilter postFilter, SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
List<ReadPost> readPostList) {this.executor = executor; PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
this.accountName = accountName; this.accountName = accountName;
this.sharedPreferences = sharedPreferences; this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences; this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.postHistorySharedPreferences = postHistorySharedPreferences;
this.name = name; this.name = name;
this.postType = postType; this.postType = postType;
this.sortType = sortType; this.sortType = sortType;
@ -317,14 +330,15 @@ public class PostViewModel extends ViewModel {
//User posts //User posts
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName, public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String username, int postType, SortType sortType, PostFilter postFilter, String where, SharedPreferences postHistorySharedPreferences, String username, int postType,
List<ReadPost> readPostList) { SortType sortType, PostFilter postFilter, String where, List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
this.accountName = accountName; this.accountName = accountName;
this.sharedPreferences = sharedPreferences; this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences; this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.postHistorySharedPreferences = postHistorySharedPreferences;
this.name = username; this.name = username;
this.postType = postType; this.postType = postType;
this.sortType = sortType; this.sortType = sortType;
@ -335,14 +349,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName, public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
String name, String query, String trendingSource, int postType, SortType sortType, SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
PostFilter postFilter, List<ReadPost> readPostList) { int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor; this.executor = executor;
this.retrofit = retrofit; this.retrofit = retrofit;
this.accessToken = accessToken; this.accessToken = accessToken;
this.accountName = accountName; this.accountName = accountName;
this.sharedPreferences = sharedPreferences; this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences; this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.postHistorySharedPreferences = postHistorySharedPreferences;
this.name = name; this.name = name;
this.query = query; this.query = query;
this.trendingSource = trendingSource; this.trendingSource = trendingSource;
@ -369,23 +384,24 @@ public class PostViewModel extends ViewModel {
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (postType == PostPagingSource.TYPE_FRONT_PAGE) { if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences, return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList); postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, postType,
sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_SEARCH) { } else if (postType == PostPagingSource.TYPE_SEARCH) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences, return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType, postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
postFilter, readPostList); trendingSource, postType, sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) { } else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences, return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, name, postType, sortType, postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
postFilter, readPostList); postType, sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) { } else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences, return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
null, name, postType, sortType, null, null, name, postType, sortType,
postFilter, null); postFilter, null);
} else { } else {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences, return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
postFeedScrolledPositionSharedPreferences, name, postType, sortType, postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
postFilter, userWhere, readPostList); postType, sortType, postFilter, userWhere, readPostList);
} }
} }
} }