mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-30 19:34:45 +01:00
Fix NSFW posts showing in SearchResultActivity when NSFW is disabled. Hide NSFW subreddit results in SearchResultActivity if NSFW is disabled.
This commit is contained in:
parent
232ea91d32
commit
2f94ef3f9a
@ -382,6 +382,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||||
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
bundle.putInt(PostFragment.EXTRA_FILTER, PostFragment.EXTRA_NO_FILTER);
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||||
mFragment.setArguments(bundle);
|
mFragment.setArguments(bundle);
|
||||||
return mFragment;
|
return mFragment;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,8 @@ public class FetchSubredditData {
|
|||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
ParseSubredditData.parseSubredditListingData(response.body(), new ParseSubredditData.ParseSubredditListingDataListener() {
|
ParseSubredditData.parseSubredditListingData(response.body(), nsfw,
|
||||||
|
new ParseSubredditData.ParseSubredditListingDataListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onParseSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
public void onParseSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
|
||||||
fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditData, after);
|
fetchSubredditListingDataListener.onFetchSubredditListingDataSuccess(subredditData, after);
|
||||||
|
@ -16,18 +16,21 @@ class ParseSubredditData {
|
|||||||
new ParseSubredditDataAsyncTask(response, parseSubredditDataListener).execute();
|
new ParseSubredditDataAsyncTask(response, parseSubredditDataListener).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parseSubredditListingData(String response, ParseSubredditListingDataListener parseSubredditListingDataListener) {
|
static void parseSubredditListingData(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) {
|
||||||
new ParseSubredditListingDataAsyncTask(response, parseSubredditListingDataListener).execute();
|
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 id = subredditDataJsonObject.getString(JSONUtils.NAME_KEY);
|
||||||
String subredditFullName = subredditDataJsonObject.getString(JSONUtils.DISPLAY_NAME_KEY);
|
String subredditFullName = subredditDataJsonObject.getString(JSONUtils.DISPLAY_NAME_KEY);
|
||||||
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
String description = subredditDataJsonObject.getString(JSONUtils.PUBLIC_DESCRIPTION_KEY).trim();
|
||||||
String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
|
String sidebarDescription = Utils.modifyMarkdown(subredditDataJsonObject.getString(JSONUtils.DESCRIPTION_KEY).trim());
|
||||||
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
|
long createdUTC = subredditDataJsonObject.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
|
||||||
String suggestedCommentSort = subredditDataJsonObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY);
|
String suggestedCommentSort = subredditDataJsonObject.getString(JSONUtils.SUGGESTED_COMMENT_SORT_KEY);
|
||||||
boolean isNSFW = !subredditDataJsonObject.isNull(JSONUtils.OVER18_KEY) && subredditDataJsonObject.getBoolean(JSONUtils.OVER18_KEY);
|
|
||||||
|
|
||||||
String bannerImageUrl;
|
String bannerImageUrl;
|
||||||
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
if (subredditDataJsonObject.isNull(JSONUtils.BANNER_BACKGROUND_IMAGE_KEY)) {
|
||||||
@ -93,7 +96,7 @@ class ParseSubredditData {
|
|||||||
try {
|
try {
|
||||||
JSONObject data = jsonResponse.getJSONObject(JSONUtils.DATA_KEY);
|
JSONObject data = jsonResponse.getJSONObject(JSONUtils.DATA_KEY);
|
||||||
mNCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
|
mNCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT_KEY);
|
||||||
subredditData = parseSubredditData(data);
|
subredditData = parseSubredditData(data, true);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
parseFailed = true;
|
parseFailed = true;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -113,15 +116,17 @@ class ParseSubredditData {
|
|||||||
|
|
||||||
private static class ParseSubredditListingDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
private static class ParseSubredditListingDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private JSONObject jsonResponse;
|
private JSONObject jsonResponse;
|
||||||
|
private boolean nsfw;
|
||||||
private boolean parseFailed;
|
private boolean parseFailed;
|
||||||
private ParseSubredditListingDataListener parseSubredditListingDataListener;
|
private ParseSubredditListingDataListener parseSubredditListingDataListener;
|
||||||
private ArrayList<SubredditData> subredditListingData;
|
private ArrayList<SubredditData> subredditListingData;
|
||||||
private String after;
|
private String after;
|
||||||
|
|
||||||
ParseSubredditListingDataAsyncTask(String response, ParseSubredditListingDataListener parseSubredditListingDataListener) {
|
ParseSubredditListingDataAsyncTask(String response, boolean nsfw, ParseSubredditListingDataListener parseSubredditListingDataListener) {
|
||||||
this.parseSubredditListingDataListener = parseSubredditListingDataListener;
|
this.parseSubredditListingDataListener = parseSubredditListingDataListener;
|
||||||
try {
|
try {
|
||||||
jsonResponse = new JSONObject(response);
|
jsonResponse = new JSONObject(response);
|
||||||
|
this.nsfw = nsfw;
|
||||||
parseFailed = false;
|
parseFailed = false;
|
||||||
subredditListingData = new ArrayList<>();
|
subredditListingData = new ArrayList<>();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -138,9 +143,11 @@ class ParseSubredditData {
|
|||||||
.getJSONArray(JSONUtils.CHILDREN_KEY);
|
.getJSONArray(JSONUtils.CHILDREN_KEY);
|
||||||
for (int i = 0; i < children.length(); i++) {
|
for (int i = 0; i < children.length(); i++) {
|
||||||
JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
JSONObject data = children.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
|
||||||
SubredditData subredditData = parseSubredditData(data);
|
SubredditData subredditData = parseSubredditData(data, nsfw);
|
||||||
|
if (subredditData != null) {
|
||||||
subredditListingData.add(subredditData);
|
subredditListingData.add(subredditData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
after = jsonResponse.getJSONObject(JSONUtils.DATA_KEY).getString(JSONUtils.AFTER_KEY);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user