aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-10-14 08:02:55 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-10-14 08:02:55 +0000
commit2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e (patch)
tree6326a93fb685fcefe5bd15407c5f48c28dbdc47e /app/src
parent232ea91d3216146d6115bd2f9d4163d2821c9175 (diff)
downloadinfinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar.gz
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar.bz2
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar.lz
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar.xz
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.tar.zst
infinity-for-reddit-2f94ef3f9af0e6fc05e2b243b3f181e6769d8b2e.zip
Fix NSFW posts showing in SearchResultActivity when NSFW is disabled. Hide NSFW subreddit results in SearchResultActivity if NSFW is disabled.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/FetchSubredditData.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java23
3 files changed, 27 insertions, 18 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
index 02c2c73a..bd6cd543 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -382,6 +382,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
mFragment.setArguments(bundle);
return mFragment;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/FetchSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/FetchSubredditData.java
index f767167b..f75ed256 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/FetchSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/FetchSubredditData.java
@@ -56,16 +56,17 @@ public class FetchSubredditData {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
if (response.isSuccessful()) {
- ParseSubredditData.parseSubredditListingData(response.body(), new ParseSubredditData.ParseSubredditListingDataListener() {
- @Override
- public void onParseSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
- fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditData, after);
- }
-
- @Override
- public void onParseSubredditListingDataFail() {
- fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
- }
+ ParseSubredditData.parseSubredditListingData(response.body(), nsfw,
+ new ParseSubredditData.ParseSubredditListingDataListener() {
+ @Override
+ public void onParseSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
+ fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditData, after);
+ }
+
+ @Override
+ public void onParseSubredditListingDataFail() {
+ fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
+ }
});
} else {
fetchSubredditListingDataListener.onFetchSubredditListingDataFail();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java
index 720e663b..4eb9aecd 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Subreddit/ParseSubredditData.java
@@ -16,18 +16,21 @@ class ParseSubredditData {
new ParseSubredditDataAsyncTask(response, parseSubredditDataListener).execute();
}
- static void parseSubredditListingData(String response, ParseSubredditListingDataListener parseSubredditListingDataListener) {
- new ParseSubredditListingDataAsyncTask(response, parseSubredditListingDataListener).execute();
+ static void parseSubredditListingData(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) {
+ new ParseSubredditListingDataAsyncTask(response, nsfw, parseSubredditListingDataListener).execute();
}
- private static SubredditData parseSubredditData(JSONObject subredditDataJsonObject) throws JSONException {
+ private static SubredditData parseSubredditData(JSONObject subredditDataJsonObject, boolean nsfw) throws JSONException {
+ boolean isNSFW = !subredditDataJsonObject.isNull(JSONUtils.OVER18_KEY) && subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY);
+ if (!nsfw && isNSFW) {
+ return null;
+ }
String id = subredditDataJsonObject.getString(JSONUtils.NAME_KEY);
String subredditFullName = subredditDataJsonObject.getString(JSONUtils.DISPLAY_NAME_KEY);
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
String suggestedCommentSort = subredditDataJsonObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY);
- boolean isNSFW = !subredditDataJsonObject.isNull(JSONUtils.OVER18_KEY) && subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY);
String bannerImageUrl;
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
@@ -93,7 +96,7 @@ class ParseSubredditData {
try {
JSONObject data = jsonResponse.getJSONObject(JSONUtils.DATA_KEY);
mNCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
- subredditData = parseSubredditData(data);
+ subredditData = parseSubredditData(data, true);
} catch (JSONException e) {
parseFailed = true;
e.printStackTrace();
@@ -113,15 +116,17 @@ class ParseSubredditData {
private static class ParseSubredditListingDataAsyncTask extends AsyncTask<Void, Void, Void> {
private JSONObject jsonResponse;
+ private boolean nsfw;
private boolean parseFailed;
private ParseSubredditListingDataListener parseSubredditListingDataListener;
private ArrayList<SubredditData> subredditListingData;
private String after;
- ParseSubredditListingDataAsyncTask(String response, ParseSubredditListingDataListener parseSubredditListingDataListener) {
+ ParseSubredditListingDataAsyncTask(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) {
this.parseSubredditListingDataListener = parseSubredditListingDataListener;
try {
jsonResponse = new JSONObject(response);
+ this.nsfw = nsfw;
parseFailed = false;
subredditListingData = new ArrayList<>();
} catch (JSONException e) {
@@ -138,8 +143,10 @@ class ParseSubredditData {
.getJSONArray(JSONUtils.CHILDREN_KEY);
for (int i = 0; i < children.length(); i++) {
JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
- SubredditData subredditData = parseSubredditData(data);
- subredditListingData.add(subredditData);
+ SubredditData subredditData = parseSubredditData(data, nsfw);
+ if (subredditData != null) {
+ subredditListingData.add(subredditData);
+ }
}
after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
}