aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java87
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java59
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java49
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java39
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java115
-rw-r--r--app/src/main/res/layout/activity_customize_post_filter.xml22
7 files changed, 273 insertions, 126 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java
index a6273e6d..990dc775 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFilter.java
@@ -1,21 +1,92 @@
package ml.docilealligator.infinityforreddit;
-import java.util.ArrayList;
+import android.os.Parcel;
+import android.os.Parcelable;
-public class PostFilter {
+public class PostFilter implements Parcelable {
public int maxVote = -1;
public int minVote = -1;
public int maxComments = -1;
public int minComments = -1;
public int maxAwards = -1;
public int minAwards = -1;
+ public boolean allowNSFW;
public boolean onlyNSFW;
public boolean onlySpoiler;
public String postTitleRegex;
- public ArrayList<String> postTitleExcludesStrings;
- public ArrayList<String> excludesSubreddits;
- public ArrayList<String> excludesUsers;
- public ArrayList<Flair> containsFlairs;
- public ArrayList<Flair> excludesFlairs;
- public ArrayList<Integer> containsPostTypes;
+ public String postTitleExcludesStrings;
+ public String excludesSubreddits;
+ public String excludesUsers;
+ public String containsFlairs;
+ public String excludesFlairs;
+ public boolean containsTextType;
+ public boolean containsLinkType;
+ public boolean containsImageType;
+ public boolean containsVideoType;
+
+ public PostFilter() {
+
+ }
+
+ protected PostFilter(Parcel in) {
+ maxVote = in.readInt();
+ minVote = in.readInt();
+ maxComments = in.readInt();
+ minComments = in.readInt();
+ maxAwards = in.readInt();
+ minAwards = in.readInt();
+ allowNSFW = in.readByte() != 0;
+ onlyNSFW = in.readByte() != 0;
+ onlySpoiler = in.readByte() != 0;
+ postTitleRegex = in.readString();
+ postTitleExcludesStrings = in.readString();
+ excludesSubreddits = in.readString();
+ excludesUsers = in.readString();
+ containsFlairs = in.readString();
+ excludesFlairs = in.readString();
+ containsTextType = in.readByte() != 0;
+ containsLinkType = in.readByte() != 0;
+ containsImageType = in.readByte() != 0;
+ containsVideoType = in.readByte() != 0;
+ }
+
+ public static final Creator<PostFilter> CREATOR = new Creator<PostFilter>() {
+ @Override
+ public PostFilter createFromParcel(Parcel in) {
+ return new PostFilter(in);
+ }
+
+ @Override
+ public PostFilter[] newArray(int size) {
+ return new PostFilter[size];
+ }
+ };
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeInt(maxVote);
+ parcel.writeInt(minVote);
+ parcel.writeInt(maxComments);
+ parcel.writeInt(minComments);
+ parcel.writeInt(maxAwards);
+ parcel.writeInt(minAwards);
+ parcel.writeByte((byte) (allowNSFW ? 1 : 0));
+ parcel.writeByte((byte) (onlyNSFW ? 1 : 0));
+ parcel.writeByte((byte) (onlySpoiler ? 1 : 0));
+ parcel.writeString(postTitleRegex);
+ parcel.writeString(postTitleExcludesStrings);
+ parcel.writeString(excludesSubreddits);
+ parcel.writeString(excludesUsers);
+ parcel.writeString(containsFlairs);
+ parcel.writeString(excludesFlairs);
+ parcel.writeByte((byte) (containsTextType ? 1 : 0));
+ parcel.writeByte((byte) (containsLinkType ? 1 : 0));
+ parcel.writeByte((byte) (containsImageType ? 1 : 0));
+ parcel.writeByte((byte) (containsVideoType ? 1 : 0));
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
index b27160f1..3fb67298 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizePostFilterActivity.java
@@ -1,5 +1,7 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.app.Activity;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Build;
@@ -26,6 +28,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
@@ -33,6 +36,8 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class CustomizePostFilterActivity extends BaseActivity {
+ public static final String RETURN_EXTRA_POST_FILTER = "REPF";
+
@BindView(R.id.coordinator_layout_customize_post_filter_activity)
CoordinatorLayout coordinatorLayout;
@BindView(R.id.appbar_layout_customize_post_filter_activity)
@@ -233,7 +238,30 @@ public class CustomizePostFilterActivity extends BaseActivity {
finish();
return true;
} else if (item.getItemId() == R.id.action_save_customize_post_filter_activity) {
+ PostFilter postFilter = new PostFilter();
+ postFilter.maxVote = maxVoteTextInputEditText.getText() == null ? -1 : Integer.parseInt(maxVoteTextInputEditText.getText().toString());
+ postFilter.minVote = minVoteTextInputEditText.getText() == null ? -1 : Integer.parseInt(minVoteTextInputEditText.getText().toString());
+ postFilter.maxComments = maxCommentsTextInputEditText.getText() == null ? -1 : Integer.parseInt(maxCommentsTextInputEditText.getText().toString());
+ postFilter.minComments = minCommentsTextInputEditText.getText() == null ? -1 : Integer.parseInt(minCommentsTextInputEditText.getText().toString());
+ postFilter.maxAwards = maxAwardsTextInputEditText.getText() == null ? -1 : Integer.parseInt(maxAwardsTextInputEditText.getText().toString());
+ postFilter.minAwards = minAwardsTextInputEditText.getText() == null ? -1 : Integer.parseInt(minAwardsTextInputEditText.getText().toString());
+ postFilter.postTitleRegex = titleExcludesRegexTextInputEditText.getText().toString();
+ postFilter.postTitleExcludesStrings = titleExcludesStringsTextInputEditText.getText().toString();
+ postFilter.excludesSubreddits = excludesSubredditsTextInputEditText.getText().toString();
+ postFilter.excludesUsers = excludesUsersTextInputEditText.getText().toString();
+ postFilter.excludesFlairs = excludesUsersTextInputEditText.getText().toString();
+ postFilter.containsFlairs = containsFlairsTextInputEditText.getText().toString();
+ postFilter.containsTextType = postTypeTextCheckBox.isChecked();
+ postFilter.containsLinkType = postTypeLinkCheckBox.isChecked();
+ postFilter.containsImageType = postTypeImageCheckBox.isChecked();
+ postFilter.containsVideoType = postTypeVideoCheckBox.isChecked();
+
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(RETURN_EXTRA_POST_FILTER, postFilter);
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ return true;
}
return 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 0b92bc36..2824e8bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -65,6 +65,7 @@ import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NetworkState;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
@@ -209,6 +210,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private int maxPosition = -1;
private int postLayout;
private SortType sortType;
+ private PostFilter postFilter;
private ColorDrawable backgroundSwipeRight;
private ColorDrawable backgroundSwipeLeft;
private Drawable drawableSwipeRight;
@@ -441,10 +443,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postType = getArguments().getInt(EXTRA_POST_TYPE);
+ //TODO: Initialize PostFilter
+ postFilter = new PostFilter();
+
int filter = getArguments().getInt(EXTRA_FILTER);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
- boolean nsfw = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
+ postFilter.allowNSFW = mNsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
savePostFeedScrolledPosition = mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_FRONT_PAGE_SCROLLED_POSITION, false);
Locale locale = getResources().getConfiguration().locale;
@@ -687,7 +692,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (accountName != null && !accountName.equals("")) {
if (readPosts == null) {
if (getArguments().getBoolean(EXTRA_DISABLE_READ_POSTS, false)) {
- initializeAndBindPostViewModel(accessToken, locale, filter, nsfw);
+ initializeAndBindPostViewModel(accessToken, locale, filter);
} else {
FetchReadPosts.fetchReadPosts(mRedditDataRoomDatabase, accountName,
postType == PostDataSource.TYPE_SUBREDDIT && subredditName != null && (subredditName.equals("all") || subredditName.equals("popular")),
@@ -695,15 +700,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
this.readPosts = readPosts;
this.subredditFilterList = subredditFilters;
- initializeAndBindPostViewModel(accessToken, locale, filter, nsfw);
+ initializeAndBindPostViewModel(accessToken, locale, filter);
}
});
}
} else {
- initializeAndBindPostViewModel(accessToken, locale, filter, nsfw);
+ initializeAndBindPostViewModel(accessToken, locale, filter);
}
} else {
- initializeAndBindPostViewModelForAnonymous(accessToken, locale, filter, nsfw);
+ initializeAndBindPostViewModelForAnonymous(accessToken, locale, filter);
}
vibrateWhenActionTriggered = mSharedPreferences.getBoolean(SharedPreferencesUtils.VIBRATE_WHEN_ACTION_TRIGGERED, true);
@@ -815,57 +820,65 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return rootView;
}
- private void initializeAndBindPostViewModel(String accessToken, Locale locale, int filter, boolean nsfw) {
+ private void initializeAndBindPostViewModel(String accessToken, Locale locale, int filter) {
if (postType == PostDataSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
+ postFilter, filter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
if (subredditName.equals("all") || subredditName.equals("popular")) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts, subredditFilterList)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
+ postFilter, filter, readPosts, subredditFilterList)).get(PostViewModel.class);
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
+ postFilter, filter, readPosts)).get(PostViewModel.class);
}
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType,
+ postFilter, filter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
+ where, filter, readPosts)).get(PostViewModel.class);
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences,
- postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postType, sortType, postFilter, filter, readPosts)).get(PostViewModel.class);
}
bindPostViewModel();
}
- private void initializeAndBindPostViewModelForAnonymous(String accessToken, Locale locale, int filter, boolean nsfw) {
+ private void initializeAndBindPostViewModelForAnonymous(String accessToken, Locale locale, int filter) {
//For anonymous user
if (postType == PostDataSource.TYPE_SEARCH) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
+ postFilter, filter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
if (subredditName.equals("all") || subredditName.equals("popular")) {
if (subredditFilterList != null) {
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts, subredditFilterList)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
+ postFilter, filter, readPosts, subredditFilterList)).get(PostViewModel.class);
} else {
FetchSubredditFilters.fetchSubredditFilters(mRedditDataRoomDatabase, subredditFilters -> {
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
subredditFilterList = subredditFilters;
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts, subredditFilterList)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, postType,
+ sortType, postFilter, filter, readPosts, subredditFilterList)).get(PostViewModel.class);
bindPostViewModel();
}
@@ -874,20 +887,23 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType, postFilter,
+ filter, readPosts)).get(PostViewModel.class);
}
} else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, multiRedditPath, postType, sortType, postFilter,
+ filter, readPosts)).get(PostViewModel.class);
} else if (postType == PostDataSource.TYPE_USER) {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences,
- postFeedScrolledPositionSharedPreferences, username, postType, sortType, where, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postFeedScrolledPositionSharedPreferences, username, postType, sortType, postFilter,
+ where, filter, readPosts)).get(PostViewModel.class);
} else {
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mOauthRetrofit, accessToken,
accountName, locale, mSharedPreferences, postFeedScrolledPositionSharedPreferences,
- postType, sortType, filter, nsfw, readPosts)).get(PostViewModel.class);
+ postType, sortType, postFilter, filter, readPosts)).get(PostViewModel.class);
}
if (mPostViewModel != null) {
@@ -1060,7 +1076,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void changeNSFW(boolean nsfw) {
- mPostViewModel.changeNSFW(nsfw);
+ postFilter.allowNSFW = nsfw;
+ mPostViewModel.changePostFilter(postFilter);
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
index e17a9a1c..8d27f6b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
@@ -12,6 +12,7 @@ import java.util.List;
import java.util.Locale;
import ml.docilealligator.infinityforreddit.NetworkState;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.apis.RedditAPI;
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
@@ -47,7 +48,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private String query;
private int postType;
private SortType sortType;
- private boolean nsfw;
+ private PostFilter postFilter;
private int filter;
private List<ReadPost> readPostList;
private List<SubredditFilter> subredditFilterList;
@@ -63,8 +64,9 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
private LoadCallback<String, Post> callback;
PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale,
- SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
- SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ SharedPreferences sharedPreferences,
+ SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
+ SortType sortType, PostFilter postFilter, int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -76,16 +78,16 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType == null ? new SortType(SortType.Type.BEST) : sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
postLinkedHashSet = new LinkedHashSet<>();
}
PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String path, int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList,
- List<SubredditFilter> subredditFilterList) {
+ String path, int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList, List<SubredditFilter> subredditFilterList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -118,16 +120,17 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
} else {
this.sortType = sortType;
}
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
this.subredditFilterList = subredditFilterList;
postLinkedHashSet = new LinkedHashSet<>();
}
PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale,
- SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditOrUserName,
- int postType, SortType sortType, String where, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
+ String subredditOrUserName, int postType, SortType sortType, PostFilter postFilter,
+ String where, int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -140,17 +143,17 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType == null ? new SortType(SortType.Type.NEW) : sortType;
+ this.postFilter = postFilter;
userWhere = where;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
postLinkedHashSet = new LinkedHashSet<>();
}
PostDataSource(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditOrUserName, String query, int postType, SortType sortType, int filter,
- boolean nsfw, List<ReadPost> readPostList) {
+ String subredditOrUserName, String query, int postType, SortType sortType, PostFilter postFilter,
+ int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -164,8 +167,8 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
hasPostLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType == null ? new SortType(SortType.Type.RELEVANCE) : sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
postLinkedHashSet = new LinkedHashSet<>();
this.readPostList = readPostList;
}
@@ -258,7 +261,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -321,7 +324,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -381,7 +384,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, subredditFilterList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList, subredditFilterList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -455,7 +458,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList, subredditFilterList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList, subredditFilterList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -516,7 +519,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -587,7 +590,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -670,7 +673,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -761,7 +764,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -821,7 +824,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -892,7 +895,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.isSuccessful()) {
- ParsePost.parsePosts(response.body(), -1, filter, nsfw, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter.allowNSFW, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
index 6d49e4d3..c0bdc023 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSourceFactory.java
@@ -9,6 +9,7 @@ import androidx.paging.DataSource;
import java.util.List;
import java.util.Locale;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter;
@@ -25,9 +26,9 @@ class PostDataSourceFactory extends DataSource.Factory {
private String query;
private int postType;
private SortType sortType;
+ private PostFilter postFilter;
private String userWhere;
private int filter;
- private boolean nsfw;
private List<ReadPost> readPostList;
private List<SubredditFilter> subredditFilterList;
@@ -37,7 +38,7 @@ class PostDataSourceFactory extends DataSource.Factory {
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences,
SharedPreferences postFeedScrolledPositionSharedPreferences, int postType,
- SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ SortType sortType, PostFilter postFilter, int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -47,15 +48,15 @@ class PostDataSourceFactory extends DataSource.Factory {
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditName, int postType, SortType sortType, int filter, boolean nsfw,
- List<ReadPost> readPostList, List<SubredditFilter> subredditFilterList) {
+ String subredditName, int postType, SortType sortType, PostFilter postFilter,
+ int filter, List<ReadPost> readPostList, List<SubredditFilter> subredditFilterList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -66,16 +67,16 @@ class PostDataSourceFactory extends DataSource.Factory {
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
this.subredditFilterList = subredditFilterList;
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditName, int postType, SortType sortType, String where, int filter,
- boolean nsfw, List<ReadPost> readPostList) {
+ String subredditName, int postType, SortType sortType, PostFilter postFilter,
+ String where, int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -86,16 +87,16 @@ class PostDataSourceFactory extends DataSource.Factory {
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
userWhere = where;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
PostDataSourceFactory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- String subredditName, String query, int postType, SortType sortType, int filter,
- boolean nsfw, List<ReadPost> readPostList) {
+ String subredditName, String query, int postType, SortType sortType, PostFilter postFilter,
+ int filter, List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -107,8 +108,8 @@ class PostDataSourceFactory extends DataSource.Factory {
postDataSourceLiveData = new MutableLiveData<>();
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
@@ -117,20 +118,20 @@ class PostDataSourceFactory extends DataSource.Factory {
public DataSource<String, Post> create() {
if (postType == PostDataSource.TYPE_FRONT_PAGE) {
postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale,
- sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType, filter,
- nsfw, readPostList);
+ sharedPreferences, postFeedScrolledPositionSharedPreferences, postType, sortType,
+ postFilter, filter, readPostList);
} else if (postType == PostDataSource.TYPE_SEARCH) {
postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale,
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, query,
- postType, sortType, filter, nsfw, readPostList);
+ postType, sortType, postFilter, filter, readPostList);
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale,
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType,
- sortType, filter, nsfw, readPostList, subredditFilterList);
+ sortType, postFilter, filter, readPostList, subredditFilterList);
} else {
postDataSource = new PostDataSource(retrofit, accessToken, accountName, locale,
sharedPreferences, postFeedScrolledPositionSharedPreferences, subredditName, postType,
- sortType, userWhere, filter, nsfw, readPostList);
+ sortType, postFilter, userWhere, filter, readPostList);
}
postDataSourceLiveData.postValue(postDataSource);
@@ -145,8 +146,8 @@ class PostDataSourceFactory extends DataSource.Factory {
return postDataSource;
}
- void changeNSFWAndSortType(boolean nsfw, SortType sortType) {
- this.nsfw = nsfw;
+ void changeSortTypeAndPostFilter(SortType sortType, PostFilter postFilter) {
this.sortType = sortType;
+ this.postFilter = postFilter;
}
}
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 c9193429..4a805ccc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostViewModel.java
@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Locale;
import ml.docilealligator.infinityforreddit.NetworkState;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter;
@@ -28,15 +29,15 @@ public class PostViewModel extends ViewModel {
private LiveData<NetworkState> initialLoadingState;
private LiveData<Boolean> hasPostLiveData;
private LiveData<PagedList<Post>> posts;
- private MutableLiveData<Boolean> nsfwLiveData;
private MutableLiveData<SortType> sortTypeLiveData;
+ private MutableLiveData<PostFilter> postFilterLiveData;
private NSFWAndSortTypeLiveData nsfwAndSortTypeLiveData;
public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences cache, int postType,
- SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ SortType sortType, PostFilter postFilter, int filter, List<ReadPost> readPostList) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale,
- sharedPreferences, cache, postType, sortType, filter, nsfw, readPostList);
+ sharedPreferences, cache, postType, sortType, postFilter, filter, readPostList);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::getInitialLoadStateLiveData);
@@ -45,12 +46,12 @@ public class PostViewModel extends ViewModel {
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::hasPostLiveData);
- nsfwLiveData = new MutableLiveData<>();
- nsfwLiveData.postValue(nsfw);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
+ postFilterLiveData = new MutableLiveData<>();
+ postFilterLiveData.postValue(postFilter);
- nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
+ nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(sortTypeLiveData, postFilterLiveData);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
@@ -59,18 +60,19 @@ public class PostViewModel extends ViewModel {
.build();
posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
- postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
+ postDataSourceFactory.changeSortTypeAndPostFilter(
+ sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
}
public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
- int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList,
- List<SubredditFilter> subredditFilterList) {
+ int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList, List<SubredditFilter> subredditFilterList) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale,
- sharedPreferences, cache, subredditName, postType, sortType, filter, nsfw, readPostList,
- subredditFilterList);
+ sharedPreferences, cache, subredditName, postType, sortType, postFilter, filter,
+ readPostList, subredditFilterList);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::getInitialLoadStateLiveData);
@@ -79,12 +81,12 @@ public class PostViewModel extends ViewModel {
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::hasPostLiveData);
- nsfwLiveData = new MutableLiveData<>();
- nsfwLiveData.postValue(nsfw);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
+ postFilterLiveData = new MutableLiveData<>();
+ postFilterLiveData.postValue(postFilter);
- nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
+ nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(sortTypeLiveData, postFilterLiveData);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
@@ -93,17 +95,19 @@ public class PostViewModel extends ViewModel {
.build();
posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
- postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
+ postDataSourceFactory.changeSortTypeAndPostFilter(
+ sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
}
public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
- int postType, SortType sortType, String where, int filter, boolean nsfw,
+ int postType, SortType sortType, PostFilter postFilter, String where, int filter,
List<ReadPost> readPostList) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale,
- sharedPreferences, cache, subredditName, postType, sortType, where, filter, nsfw, readPostList);
+ sharedPreferences, cache, subredditName, postType, sortType, postFilter, where, filter,
+ readPostList);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::getInitialLoadStateLiveData);
@@ -112,12 +116,12 @@ public class PostViewModel extends ViewModel {
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::hasPostLiveData);
- nsfwLiveData = new MutableLiveData<>();
- nsfwLiveData.postValue(nsfw);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
+ postFilterLiveData = new MutableLiveData<>();
+ postFilterLiveData.postValue(postFilter);
- nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
+ nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(sortTypeLiveData, postFilterLiveData);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
@@ -126,17 +130,19 @@ public class PostViewModel extends ViewModel {
.build();
posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
- postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
+ postDataSourceFactory.changeSortTypeAndPostFilter(
+ sortTypeLiveData.getValue(), postFilterLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
}
public PostViewModel(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
- String query, int postType, SortType sortType, int filter, boolean nsfw,
+ String query, int postType, SortType sortType, PostFilter postFilter, int filter,
List<ReadPost> readPostList) {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, accountName, locale,
- sharedPreferences, cache, subredditName, query, postType, sortType, filter, nsfw, readPostList);
+ sharedPreferences, cache, subredditName, query, postType, sortType, postFilter, filter,
+ readPostList);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::getInitialLoadStateLiveData);
@@ -145,12 +151,12 @@ public class PostViewModel extends ViewModel {
hasPostLiveData = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
PostDataSource::hasPostLiveData);
- nsfwLiveData = new MutableLiveData<>();
- nsfwLiveData.postValue(nsfw);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
+ postFilterLiveData = new MutableLiveData<>();
+ postFilterLiveData.postValue(postFilter);
- nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData);
+ nsfwAndSortTypeLiveData = new NSFWAndSortTypeLiveData(sortTypeLiveData, postFilterLiveData);
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder())
@@ -159,7 +165,8 @@ public class PostViewModel extends ViewModel {
.build();
posts = Transformations.switchMap(nsfwAndSortTypeLiveData, nsfwAndSort -> {
- postDataSourceFactory.changeNSFWAndSortType(nsfwLiveData.getValue(), sortTypeLiveData.getValue());
+ postDataSourceFactory.changeSortTypeAndPostFilter(sortTypeLiveData.getValue(),
+ postFilterLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
}
@@ -192,8 +199,8 @@ public class PostViewModel extends ViewModel {
sortTypeLiveData.postValue(sortType);
}
- public void changeNSFW(boolean nsfw) {
- nsfwLiveData.postValue(nsfw);
+ public void changePostFilter(PostFilter postFilter) {
+ postFilterLiveData.postValue(postFilter);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory {
@@ -207,15 +214,16 @@ public class PostViewModel extends ViewModel {
private String query;
private int postType;
private SortType sortType;
+ private PostFilter postFilter;
private String userWhere;
private int filter;
- private boolean nsfw;
private List<ReadPost> readPostList;
private List<SubredditFilter> subredditFilterList;
public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
- int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -224,14 +232,16 @@ public class PostViewModel extends ViewModel {
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
- SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
- int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ SharedPreferences sharedPreferences,
+ SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
+ int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -241,16 +251,17 @@ public class PostViewModel extends ViewModel {
this.subredditName = subredditName;
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
//With subreddit filter
public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
- SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
- int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList,
- List<SubredditFilter> subredditFilterList) {
+ SharedPreferences sharedPreferences,
+ SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
+ int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList, List<SubredditFilter> subredditFilterList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -260,8 +271,8 @@ public class PostViewModel extends ViewModel {
this.subredditName = subredditName;
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
this.subredditFilterList = subredditFilterList;
}
@@ -269,7 +280,8 @@ public class PostViewModel extends ViewModel {
//User posts
public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
- int postType, SortType sortType, String where, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ int postType, SortType sortType, PostFilter postFilter, String where, int filter,
+ List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -279,15 +291,16 @@ public class PostViewModel extends ViewModel {
this.subredditName = subredditName;
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
userWhere = where;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
public Factory(Retrofit retrofit, String accessToken, String accountName, Locale locale,
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences, String subredditName,
- String query, int postType, SortType sortType, int filter, boolean nsfw, List<ReadPost> readPostList) {
+ String query, int postType, SortType sortType, PostFilter postFilter, int filter,
+ List<ReadPost> readPostList) {
this.retrofit = retrofit;
this.accessToken = accessToken;
this.accountName = accountName;
@@ -298,8 +311,8 @@ public class PostViewModel extends ViewModel {
this.query = query;
this.postType = postType;
this.sortType = sortType;
+ this.postFilter = postFilter;
this.filter = filter;
- this.nsfw = nsfw;
this.readPostList = readPostList;
}
@@ -308,27 +321,27 @@ public class PostViewModel extends ViewModel {
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
if (postType == PostDataSource.TYPE_FRONT_PAGE) {
return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences,
- postFeedScrolledPositionSharedPreferences, postType, sortType, filter, nsfw, readPostList);
+ postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, filter, readPostList);
} else if (postType == PostDataSource.TYPE_SEARCH) {
return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences,
postFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
- filter, nsfw, readPostList);
+ postFilter, filter, readPostList);
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences,
postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
- filter, nsfw, readPostList, subredditFilterList);
+ postFilter, filter, readPostList, subredditFilterList);
} else {
return (T) new PostViewModel(retrofit, accessToken, accountName, locale, sharedPreferences,
postFeedScrolledPositionSharedPreferences, subredditName, postType, sortType,
- userWhere, filter, nsfw, readPostList);
+ postFilter, userWhere, filter, readPostList);
}
}
}
- private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, SortType>> {
- public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<SortType> sortType) {
- addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue())));
- addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1)));
+ private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<PostFilter, SortType>> {
+ public NSFWAndSortTypeLiveData(LiveData<SortType> sortTypeLiveData, LiveData<PostFilter> postFilterLiveData) {
+ addSource(sortTypeLiveData, sortType -> setValue(Pair.create(postFilterLiveData.getValue(), sortType)));
+ addSource(postFilterLiveData, postFilter -> setValue(Pair.create(postFilter, sortTypeLiveData.getValue())));
}
}
}
diff --git a/app/src/main/res/layout/activity_customize_post_filter.xml b/app/src/main/res/layout/activity_customize_post_filter.xml
index ff4b0598..727ebe58 100644
--- a/app/src/main/res/layout/activity_customize_post_filter.xml
+++ b/app/src/main/res/layout/activity_customize_post_filter.xml
@@ -61,7 +61,9 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
- android:text="@string/bottom_sheet_post_text" />
+ android:text="@string/bottom_sheet_post_text"
+ android:fontFamily="?attr/font_default"
+ android:textSize="?attr/font_default" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/post_type_text_check_box_customize_post_filter_activity"
@@ -89,7 +91,9 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
- android:text="@string/bottom_sheet_post_link" />
+ android:text="@string/bottom_sheet_post_link"
+ android:fontFamily="?attr/font_default"
+ android:textSize="?attr/font_default" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/post_type_link_check_box_customize_post_filter_activity"
@@ -117,7 +121,9 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
- android:text="@string/bottom_sheet_post_image" />
+ android:text="@string/bottom_sheet_post_image"
+ android:fontFamily="?attr/font_default"
+ android:textSize="?attr/font_default" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/post_type_image_check_box_customize_post_filter_activity"
@@ -145,7 +151,9 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
- android:text="@string/bottom_sheet_post_video" />
+ android:text="@string/bottom_sheet_post_video"
+ android:fontFamily="?attr/font_default"
+ android:textSize="?attr/font_default" />
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/post_type_video_check_box_customize_post_filter_activity"
@@ -289,6 +297,7 @@
android:id="@+id/min_vote_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/min_vote_hint" />
@@ -309,6 +318,7 @@
android:id="@+id/max_vote_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/max_vote_hint" />
@@ -329,6 +339,7 @@
android:id="@+id/min_comments_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/min_comments_hint" />
@@ -349,6 +360,7 @@
android:id="@+id/max_comments_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/max_comments_hint" />
@@ -369,6 +381,7 @@
android:id="@+id/min_awards_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/min_awards_hint" />
@@ -389,6 +402,7 @@
android:id="@+id/max_awards_text_input_edit_text_customize_post_filter_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:inputType="numberSigned"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default"
android:hint="@string/max_awards_hint" />