aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-18 05:15:50 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-18 05:15:50 +0000
commitfbc47e62261d98c6034ff14f178779d14a214b9e (patch)
treeb4d0474218e28a060319941e0dd6946af33998c6 /app/src
parentc5cedba37019aac94eecc0167abc08957825f2ba (diff)
downloadinfinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar.gz
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar.bz2
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar.lz
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar.xz
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.tar.zst
infinity-for-reddit-fbc47e62261d98c6034ff14f178779d14a214b9e.zip
Continue adding support for post filter.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java29
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java20
2 files changed, 26 insertions, 23 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index e4a7303c..a67f2ed8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -13,6 +13,7 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import ml.docilealligator.infinityforreddit.PostFilter;
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
import ml.docilealligator.infinityforreddit.readpost.ReadPost;
import ml.docilealligator.infinityforreddit.subredditfilter.SubredditFilter;
@@ -24,18 +25,20 @@ import ml.docilealligator.infinityforreddit.utils.Utils;
*/
public class ParsePost {
- public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, List<ReadPost> readPostList,
+ public static void parsePosts(String response, int nPosts, int filter, PostFilter postFilter, List<ReadPost> readPostList,
ParsePostsListingListener parsePostsListingListener) {
- new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, readPostList, parsePostsListingListener).execute();
+ new ParsePostDataAsyncTask(response, nPosts, filter, postFilter, readPostList, parsePostsListingListener).execute();
}
- public static void parsePosts(String response, int nPosts, int filter, boolean nsfw, List<ReadPost> readPostList,
+ public static void parsePosts(String response, int nPosts, int filter, PostFilter postFilter, List<ReadPost> readPostList,
List<SubredditFilter> subredditFilterList, ParsePostsListingListener parsePostsListingListener) {
- new ParsePostDataAsyncTask(response, nPosts, filter, nsfw, readPostList, subredditFilterList, parsePostsListingListener).execute();
+ new ParsePostDataAsyncTask(response, nPosts, filter, postFilter, readPostList, subredditFilterList, parsePostsListingListener).execute();
}
public static void parsePost(String response, ParsePostListener parsePostListener) {
- new ParsePostDataAsyncTask(response, true, parsePostListener).execute();
+ PostFilter postFilter = new PostFilter();
+ postFilter.allowNSFW = true;
+ new ParsePostDataAsyncTask(response, postFilter, parsePostListener).execute();
}
private static Post parseBasicData(JSONObject data) throws JSONException {
@@ -491,7 +494,7 @@ public class ParsePost {
private JSONArray allData;
private int nPosts;
private int filter;
- private boolean nsfw;
+ private PostFilter postFilter;
private List<ReadPost> readPostList;
private List<SubredditFilter> subredditFilterList;
private ParsePostsListingListener parsePostsListingListener;
@@ -501,7 +504,7 @@ public class ParsePost {
private String lastItem;
private boolean parseFailed;
- ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, List<ReadPost> readPostList,
+ ParsePostDataAsyncTask(String response, int nPosts, int filter, PostFilter postFilter, List<ReadPost> readPostList,
ParsePostsListingListener parsePostsListingListener) {
this.parsePostsListingListener = parsePostsListingListener;
try {
@@ -510,7 +513,7 @@ public class ParsePost {
lastItem = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
this.nPosts = nPosts;
this.filter = filter;
- this.nsfw = nsfw;
+ this.postFilter = postFilter;
this.readPostList = readPostList;
newPosts = new LinkedHashSet<>();
parseFailed = false;
@@ -520,18 +523,18 @@ public class ParsePost {
}
}
- ParsePostDataAsyncTask(String response, int nPosts, int filter, boolean nsfw, List<ReadPost> readPostList,
+ ParsePostDataAsyncTask(String response, int nPosts, int filter, PostFilter postFilter, List<ReadPost> readPostList,
List<SubredditFilter> subredditFilterList, ParsePostsListingListener parsePostsListingListener) {
- this(response, nPosts, filter, nsfw, readPostList, parsePostsListingListener);
+ this(response, nPosts, filter, postFilter, readPostList, parsePostsListingListener);
this.subredditFilterList = subredditFilterList;
}
- ParsePostDataAsyncTask(String response, boolean nsfw,
+ ParsePostDataAsyncTask(String response, PostFilter postFilter,
ParsePostListener parsePostListener) {
this.parsePostListener = parsePostListener;
try {
allData = new JSONArray(response).getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
- this.nsfw = nsfw;
+ this.postFilter = postFilter;
parseFailed = false;
} catch (JSONException e) {
e.printStackTrace();
@@ -589,7 +592,7 @@ public class ParsePost {
}
}
}
- if (availablePost && !(!nsfw && post.isNSFW())) {
+ if (availablePost && !(!postFilter.allowNSFW && post.isNSFW())) {
if (filter == PostFragment.EXTRA_NO_FILTER) {
newPosts.add(post);
} else if (filter == post.getPostType()) {
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 8d27f6b0..c2fff1e6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/PostDataSource.java
@@ -261,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -324,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -384,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, postFilter.allowNSFW, readPostList, subredditFilterList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList, subredditFilterList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -458,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, postFilter.allowNSFW, readPostList, subredditFilterList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList, subredditFilterList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -519,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -590,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -673,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -764,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -824,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {
@@ -895,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, postFilter.allowNSFW, readPostList,
+ ParsePost.parsePosts(response.body(), -1, filter, postFilter, readPostList,
new ParsePost.ParsePostsListingListener() {
@Override
public void onParsePostsListingSuccess(LinkedHashSet<Post> newPosts, String lastItem) {