aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java53
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java68
3 files changed, 65 insertions, 58 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index 1fd1664b..e8935f5f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -194,7 +194,6 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
private boolean mMarkPostsAsRead;
private boolean mMarkPostsAsReadAfterVoting;
private boolean mMarkPostsAsReadOnScroll;
- private boolean mHideReadPostsAutomatically;
private boolean mHidePostType;
private boolean mHidePostFlair;
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);
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);
- mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false);
mHidePostType = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_TYPE, false);
mHidePostFlair = sharedPreferences.getBoolean(SharedPreferencesUtils.HIDE_POST_FLAIR, false);
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 5d2af420..745cdc1e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -49,18 +49,15 @@ import androidx.transition.TransitionManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
-import com.google.common.collect.Lists;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
-import java.util.Set;
import java.util.concurrent.Executor;
import javax.inject.Inject;
@@ -1082,31 +1079,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
- postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
+ mPostFeedScrolledPositionSharedPreferences, mPostHistorySharedPreferences, subredditName,
+ query, trendingSource, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
- postFilter, readPosts)).get(PostViewModel.class);
+ accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
+ mPostHistorySharedPreferences, subredditName, postType, sortType, postFilter, readPosts))
+ .get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType,
- postFilter, readPosts)).get(PostViewModel.class);
+ accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
+ mPostHistorySharedPreferences, multiRedditPath, postType, sortType, postFilter, readPosts))
+ .get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
- where, readPosts)).get(PostViewModel.class);
+ accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
+ mPostHistorySharedPreferences, username, postType, sortType, postFilter, where, readPosts))
+ .get(PostViewModel.class);
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
mOauthRetrofit, accessToken,
accountName, mSharedPreferences, mPostFeedScrolledPositionSharedPreferences,
- postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
+ mPostHistorySharedPreferences, postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
}
bindPostViewModel();
@@ -1116,33 +1113,29 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
//For anonymous user
if (postType == PostPagingSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
- mRetrofit, null,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
+ mRetrofit, null, accountName, mSharedPreferences,
+ mPostFeedScrolledPositionSharedPreferences, null, subredditName, query, trendingSource,
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT) {
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
- mRetrofit, null,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
+ mRetrofit, null, accountName, mSharedPreferences,
+ mPostFeedScrolledPositionSharedPreferences, null, subredditName, postType, sortType,
postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
- mRetrofit, null,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter,
- readPosts)).get(PostViewModel.class);
+ mRetrofit, null, accountName, mSharedPreferences,
+ mPostFeedScrolledPositionSharedPreferences, null, multiRedditPath,
+ postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
} else if (postType == PostPagingSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
- mRetrofit, null,
- accountName, mSharedPreferences,
- mPostFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
+ mRetrofit, null, accountName, mSharedPreferences,
+ mPostFeedScrolledPositionSharedPreferences, null, username, postType, sortType, postFilter,
where, readPosts)).get(PostViewModel.class);
} else {
//Anonymous Front Page
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
- mRetrofit,
- mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter)).get(PostViewModel.class);
+ mRetrofit, mSharedPreferences, concatenatedSubredditNames, postType, sortType, postFilter))
+ .get(PostViewModel.class);
}
bindPostViewModel();
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 4f9a3890..ca574517 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
@@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit.post;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MediatorLiveData;
@@ -18,12 +19,12 @@ import androidx.paging.PagingDataTransforms;
import androidx.paging.PagingLiveData;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.postfilter.PostFilter;
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class PostViewModel extends ViewModel {
@@ -51,7 +52,8 @@ public class PostViewModel extends ViewModel {
private SortTypeAndPostFilterLiveData sortTypeAndPostFilterLiveData;
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) {
this.executor = executor;
this.retrofit = retrofit;
@@ -86,13 +88,14 @@ public class PostViewModel extends ViewModel {
postPagingData, executor,
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,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditName, int postType, SortType sortType, PostFilter postFilter,
- List<ReadPost> readPostList) {
+ @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, int postType,
+ SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
this.executor = executor;
this.retrofit = retrofit;
this.accessToken = accessToken;
@@ -127,12 +130,14 @@ public class PostViewModel extends ViewModel {
postPagingData, executor,
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,
SharedPreferences sharedPreferences,
- SharedPreferences postFeedScrolledPositionSharedPreferences, String username,
+ SharedPreferences postFeedScrolledPositionSharedPreferences,
+ @Nullable SharedPreferences postHistorySharedPreferences, String username,
int postType, SortType sortType, PostFilter postFilter, String userWhere,
List<ReadPost> readPostList) {
this.executor = executor;
@@ -170,13 +175,15 @@ public class PostViewModel extends ViewModel {
postPagingData, executor,
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,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditName, String query, String trendingSource, int postType, SortType sortType,
- PostFilter postFilter, List<ReadPost> readPostList) {
+ @Nullable SharedPreferences postHistorySharedPreferences, String subredditName, String query,
+ String trendingSource, int postType, SortType sortType, PostFilter postFilter,
+ List<ReadPost> readPostList) {
this.executor = executor;
this.retrofit = retrofit;
this.accessToken = accessToken;
@@ -213,7 +220,8 @@ public class PostViewModel extends ViewModel {
postPagingData, executor,
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() {
@@ -274,6 +282,7 @@ public class PostViewModel extends ViewModel {
private String accountName;
private SharedPreferences sharedPreferences;
private SharedPreferences postFeedScrolledPositionSharedPreferences;
+ private SharedPreferences postHistorySharedPreferences;
private String name;
private String query;
private String trendingSource;
@@ -285,13 +294,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
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.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postHistorySharedPreferences = postHistorySharedPreferences;
this.postType = postType;
this.sortType = sortType;
this.postFilter = postFilter;
@@ -300,13 +311,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String name, int postType, SortType sortType, PostFilter postFilter,
- List<ReadPost> readPostList) {this.executor = executor;
+ SharedPreferences postHistorySharedPreferences, String name, int postType, SortType sortType,
+ PostFilter postFilter, List<ReadPost> 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.postType = postType;
this.sortType = sortType;
@@ -317,14 +330,15 @@ public class PostViewModel extends ViewModel {
//User posts
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String username, int postType, SortType sortType, PostFilter postFilter, String where,
- List<ReadPost> readPostList) {
+ SharedPreferences postHistorySharedPreferences, String username, int postType,
+ SortType sortType, PostFilter postFilter, String where, List<ReadPost> readPostList) {
this.executor = executor;
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
this.sharedPreferences = sharedPreferences;
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
+ this.postHistorySharedPreferences = postHistorySharedPreferences;
this.name = username;
this.postType = postType;
this.sortType = sortType;
@@ -335,14 +349,15 @@ public class PostViewModel extends ViewModel {
public Factory(Executor executor, Retrofit retrofit, String accessToken, String accountName,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String name, String query, String trendingSource, int postType, SortType sortType,
- PostFilter postFilter, List<ReadPost> readPostList) {
+ SharedPreferences postHistorySharedPreferences, String name, String query, String trendingSource,
+ int postType, SortType sortType, PostFilter postFilter, List<ReadPost> 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.trendingSource = trendingSource;
@@ -369,23 +384,24 @@ public class PostViewModel extends ViewModel {
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (postType == PostPagingSource.TYPE_FRONT_PAGE) {
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) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
- postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType,
- postFilter, readPostList);
+ postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name, query,
+ trendingSource, postType, sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_SUBREDDIT || postType == PostPagingSource.TYPE_MULTI_REDDIT) {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
- postFeedScrolledPositionSharedPreferences, name, postType, sortType,
- postFilter, readPostList);
+ postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
+ postType, sortType, postFilter, readPostList);
} else if (postType == PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE) {
return (T) new PostViewModel(executor, retrofit, null, null, sharedPreferences,
- null, name, postType, sortType,
+ null, null, name, postType, sortType,
postFilter, null);
} else {
return (T) new PostViewModel(executor, retrofit, accessToken, accountName, sharedPreferences,
- postFeedScrolledPositionSharedPreferences, name, postType, sortType,
- postFilter, userWhere, readPostList);
+ postFeedScrolledPositionSharedPreferences, postHistorySharedPreferences, name,
+ postType, sortType, postFilter, userWhere, readPostList);
}
}
}