New option: Do not blur nsfw media in nsfw subreddits.

This commit is contained in:
Alex Ning 2021-03-12 11:43:44 +08:00
parent 2efb890100
commit 6beb448540
15 changed files with 128 additions and 33 deletions

View File

@ -80,7 +80,7 @@ import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenc
import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NotificationPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.NotificationPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment; import ml.docilealligator.infinityforreddit.settings.NsfwAndSpoilerFragment;
import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment; import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
import ml.docilealligator.infinityforreddit.settings.SecurityPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.SecurityPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.ThemePreferenceFragment; import ml.docilealligator.infinityforreddit.settings.ThemePreferenceFragment;
@ -224,7 +224,7 @@ public interface AppComponent {
void inject(SecurityPreferenceFragment securityPreferenceFragment); void inject(SecurityPreferenceFragment securityPreferenceFragment);
void inject(NsfwAndBlurringFragment nsfwAndBlurringFragment); void inject(NsfwAndSpoilerFragment nsfwAndSpoilerFragment);
void inject(CustomizeBottomAppBarFragment customizeBottomAppBarFragment); void inject(CustomizeBottomAppBarFragment customizeBottomAppBarFragment);

View File

@ -32,6 +32,7 @@ public class LinkResolverActivity extends AppCompatActivity {
public static final String EXTRA_IS_NSFW = "EIN"; public static final String EXTRA_IS_NSFW = "EIN";
private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/?\\w+/?"; private static final String POST_PATTERN = "/r/\\w+/comments/\\w+/?\\w+/?";
private static final String POST_PATTERN_2 = "/(u|U|user)/\\w+/comments/\\w+/?\\w+/?";
private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/?\\w+/\\w+/?"; private static final String COMMENT_PATTERN = "/(r|u|U|user)/\\w+/comments/\\w+/?\\w+/\\w+/?";
private static final String SUBREDDIT_PATTERN = "/[rR]/[\\w-]+/?"; private static final String SUBREDDIT_PATTERN = "/[rR]/[\\w-]+/?";
private static final String USER_PATTERN = "/(u|U|user)/[\\w-]+/?"; private static final String USER_PATTERN = "/(u|U|user)/[\\w-]+/?";
@ -125,7 +126,7 @@ public class LinkResolverActivity extends AppCompatActivity {
} else if (path.isEmpty()) { } else if (path.isEmpty()) {
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
startActivity(intent); startActivity(intent);
} else if (path.matches(POST_PATTERN)) { } else if (path.matches(POST_PATTERN) || path.matches(POST_PATTERN_2)) {
int commentsIndex = segments.lastIndexOf("comments"); int commentsIndex = segments.lastIndexOf("comments");
if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) {
Intent intent = new Intent(this, ViewPostDetailActivity.class); Intent intent = new Intent(this, ViewPostDetailActivity.class);

View File

@ -33,7 +33,7 @@ import ml.docilealligator.infinityforreddit.settings.FontPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment; import ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment; import ml.docilealligator.infinityforreddit.settings.NsfwAndSpoilerFragment;
import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment; import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@ -155,8 +155,8 @@ public class SettingsActivity extends BaseActivity implements
pref.getFragment()); pref.getFragment());
if (fragment instanceof CustomizeMainPageTabsFragment) { if (fragment instanceof CustomizeMainPageTabsFragment) {
args.putString(CustomizeMainPageTabsFragment.EXTRA_ACCOUNT_NAME, mAccountName); args.putString(CustomizeMainPageTabsFragment.EXTRA_ACCOUNT_NAME, mAccountName);
} else if (fragment instanceof NsfwAndBlurringFragment) { } else if (fragment instanceof NsfwAndSpoilerFragment) {
args.putString(NsfwAndBlurringFragment.EXTRA_ACCOUNT_NAME, mAccountName); args.putString(NsfwAndSpoilerFragment.EXTRA_ACCOUNT_NAME, mAccountName);
} else if (fragment instanceof CustomizeBottomAppBarFragment) { } else if (fragment instanceof CustomizeBottomAppBarFragment) {
args.putString(CustomizeBottomAppBarFragment.EXTRA_ACCOUNT_NAME, mAccountName); args.putString(CustomizeBottomAppBarFragment.EXTRA_ACCOUNT_NAME, mAccountName);
} else if (fragment instanceof PostHistoryFragment) { } else if (fragment instanceof PostHistoryFragment) {

View File

@ -69,6 +69,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
public static final String EXTRA_MESSAGE_FULLNAME = "ENI"; public static final String EXTRA_MESSAGE_FULLNAME = "ENI";
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
public static final String EXTRA_POST_FRAGMENT_ID = "EPFI"; public static final String EXTRA_POST_FRAGMENT_ID = "EPFI";
public static final String EXTRA_IS_NSFW_SUBREDDIT = "EINS";
public static final int EDIT_COMMENT_REQUEST_CODE = 3; public static final int EDIT_COMMENT_REQUEST_CODE = 3;
public static final int GIVE_AWARD_REQUEST_CODE = 100; public static final int GIVE_AWARD_REQUEST_CODE = 100;
@State @State
@ -108,6 +109,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
private int postListPosition = -1; private int postListPosition = -1;
private int orientation; private int orientation;
private boolean mVolumeKeysNavigateComments; private boolean mVolumeKeysNavigateComments;
private boolean isNsfwSubreddit;
@Override @Override
@ -163,6 +165,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
EventBus.getDefault().post(new NeedForPostListFromPostFragmentEvent(postFragmentId)); EventBus.getDefault().post(new NeedForPostListFromPostFragmentEvent(postFragmentId));
} }
isNsfwSubreddit = getIntent().getBooleanExtra(EXTRA_IS_NSFW_SUBREDDIT, false);
fragmentManager = getSupportFragmentManager(); fragmentManager = getSupportFragmentManager();
if (savedInstanceState == null) { if (savedInstanceState == null) {
@ -258,6 +262,10 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele
} }
} }
public boolean isNsfwSubreddit() {
return isNsfwSubreddit;
}
private void editComment(String commentAuthor, String commentContentMarkdown, int position) { private void editComment(String commentAuthor, String commentContentMarkdown, int position) {
if (sectionsPagerAdapter != null) { if (sectionsPagerAdapter != null) {
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();

View File

@ -201,6 +201,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private String subredditName; private String subredditName;
private boolean mFetchSubredditInfoSuccess = false; private boolean mFetchSubredditInfoSuccess = false;
private int mNCurrentOnlineSubscribers = 0; private int mNCurrentOnlineSubscribers = 0;
private boolean isNsfwSubreddit = false;
private boolean subscriptionReady = false; private boolean subscriptionReady = false;
private boolean isInLazyMode = false; private boolean isInLazyMode = false;
private boolean showToast = false; private boolean showToast = false;
@ -364,6 +365,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
.get(SubredditViewModel.class); .get(SubredditViewModel.class);
mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> { mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
if (subredditData != null) { if (subredditData != null) {
isNsfwSubreddit = subredditData.isNSFW();
if (subredditData.getBannerUrl().equals("")) { if (subredditData.getBannerUrl().equals("")) {
iconGifImageView.setOnClickListener(view -> { iconGifImageView.setOnClickListener(view -> {
//Do nothing as it has no image //Do nothing as it has no image
@ -1111,6 +1114,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
EventBus.getDefault().unregister(this); EventBus.getDefault().unregister(this);
} }
public boolean isNsfwSubreddit() {
return isNsfwSubreddit;
}
private void makeSnackbar(int resId, boolean retry) { private void makeSnackbar(int resId, boolean retry) {
if (showToast) { if (showToast) {
Toast.makeText(this, resId, Toast.LENGTH_SHORT).show(); Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();

View File

@ -164,6 +164,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private String mSingleCommentId; private String mSingleCommentId;
private boolean mIsSingleCommentThreadMode; private boolean mIsSingleCommentThreadMode;
private boolean mNeedBlurNsfw; private boolean mNeedBlurNsfw;
private boolean mDoNotBlurNsfwInNsfwSubreddits;
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
@ -476,6 +477,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mIsSingleCommentThreadMode = isSingleCommentThreadMode; mIsSingleCommentThreadMode = isSingleCommentThreadMode;
mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
mDoNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
@ -1540,7 +1542,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
}); });
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { if (mImageViewWidth > preview.getPreviewWidth()) {
@ -1571,7 +1573,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
}); });
if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView); .into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else { } else {
@ -1603,7 +1605,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
}); });
if ((mPost.isNSFW() && mNeedBlurNsfw) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView); .into(((PostDetailLinkViewHolder) holder).mImageView);
} else { } else {
@ -1635,7 +1637,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
}); });
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) { if ((mPost.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView); imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else { } else {
if (mImageViewWidth > preview.getPreviewWidth()) { if (mImageViewWidth > preview.getPreviewWidth()) {
@ -1870,8 +1872,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} }
} }
public void setBlurNSFW(boolean needBlurNSFW) { public void setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(boolean needBlurNsfw, boolean doNotBlurNsfwInNsfwSubreddits) {
mNeedBlurNsfw = needBlurNSFW; mNeedBlurNsfw = needBlurNsfw;
mDoNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits;
} }
public void setBlurSpoiler(boolean needBlurSpoiler) { public void setBlurSpoiler(boolean needBlurSpoiler) {

View File

@ -186,7 +186,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private float mScale; private float mScale;
private boolean mDisplaySubredditName; private boolean mDisplaySubredditName;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mNeedBlurNSFW; private boolean mNeedBlurNsfw;
private boolean mDoNotBlurNsfwInNsfwSubreddits;
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private String mTimeFormatPattern; private String mTimeFormatPattern;
@ -240,7 +241,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mAccessToken = accessToken; mAccessToken = accessToken;
mPostType = postType; mPostType = postType;
mDisplaySubredditName = displaySubredditName; mDisplaySubredditName = displaySubredditName;
mNeedBlurNSFW = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); mNeedBlurNsfw = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
mDoNotBlurNsfwInNsfwSubreddits = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); mNeedBlurSpoiler = nsfwAndSpoilerSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false); mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
@ -1501,7 +1503,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
}); });
if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostWithPreviewTypeViewHolder) holder).imageView); .into(((PostWithPreviewTypeViewHolder) holder).imageView);
} else { } else {
@ -1535,7 +1537,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return false; return false;
} }
}); });
if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit())) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder imageRequestBuilder
.transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView); .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView);
} else { } else {
@ -1570,7 +1572,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
}); });
if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostGalleryViewHolder) holder).imageView); .into(((PostGalleryViewHolder) holder).imageView);
} else { } else {
@ -1608,7 +1610,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
} }
}); });
if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) { if ((post.isNSFW() && mNeedBlurNsfw && !(mDoNotBlurNsfwInNsfwSubreddits && mFragment != null && mFragment.getIsNsfwSubreddit()) && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))) imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostCard2WithPreviewViewHolder) holder).imageView); .into(((PostCard2WithPreviewViewHolder) holder).imageView);
} else { } else {
@ -1668,8 +1670,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mPostLayout = postLayout; mPostLayout = postLayout;
} }
public void setBlurNSFW(boolean needBlurNSFW) { public void setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(boolean needBlurNsfw, boolean doNotBlurNsfwInNsfwSubreddits) {
mNeedBlurNSFW = needBlurNSFW; mNeedBlurNsfw = needBlurNsfw;
mDoNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits;
} }
public void setBlurSpoiler(boolean needBlurSpoiler) { public void setBlurSpoiler(boolean needBlurSpoiler) {
@ -2023,6 +2026,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, post);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_LIST_POSITION, position);
intent.putExtra(ViewPostDetailActivity.EXTRA_POST_FRAGMENT_ID, mFragment.getPostFragmentId()); intent.putExtra(ViewPostDetailActivity.EXTRA_POST_FRAGMENT_ID, mFragment.getPostFragmentId());
intent.putExtra(ViewPostDetailActivity.EXTRA_IS_NSFW_SUBREDDIT, mFragment.getIsNsfwSubreddit());
mActivity.startActivity(intent); mActivity.startActivity(intent);
} }

View File

@ -2,8 +2,10 @@ package ml.docilealligator.infinityforreddit.events;
public class ChangeNSFWBlurEvent { public class ChangeNSFWBlurEvent {
public boolean needBlurNSFW; public boolean needBlurNSFW;
public boolean doNotBlurNsfwInNsfwSubreddits;
public ChangeNSFWBlurEvent(boolean needBlurNSFW) { public ChangeNSFWBlurEvent(boolean needBlurNSFW, boolean doNotBlurNsfwInNsfwSubreddits) {
this.needBlurNSFW = needBlurNSFW; this.needBlurNSFW = needBlurNSFW;
this.doNotBlurNsfwInNsfwSubreddits = doNotBlurNsfwInNsfwSubreddits;
} }
} }

View File

@ -75,6 +75,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
@ -1476,6 +1477,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
} }
public boolean getIsNsfwSubreddit() {
if (activity instanceof ViewSubredditDetailActivity) {
return ((ViewSubredditDetailActivity) activity).isNsfwSubreddit();
} else {
return false;
}
}
@Subscribe @Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) { public void onPostUpdateEvent(PostUpdateEventToPostList event) {
PagedList<Post> posts = mAdapter.getCurrentList(); PagedList<Post> posts = mAdapter.getCurrentList();
@ -1522,7 +1531,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Subscribe @Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
if (mAdapter != null) { if (mAdapter != null) {
mAdapter.setBlurNSFW(event.needBlurNSFW); mAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits);
refreshAdapter(); refreshAdapter();
} }
} }

View File

@ -1664,6 +1664,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
}); });
} }
public boolean getIsNsfwSubreddit() {
if (activity != null) {
return activity.isNsfwSubreddit();
}
return false;
}
@Subscribe @Subscribe
public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) { public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) {
if (mPost.getId().equals(event.post.getId())) { if (mPost.getId().equals(event.post.getId())) {
@ -1682,7 +1689,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
@Subscribe @Subscribe
public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) {
mAdapter.setBlurNSFW(event.needBlurNSFW); mAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits);
refreshAdapter(); refreshAdapter();
} }

View File

@ -22,14 +22,14 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class NsfwAndBlurringFragment extends Fragment { public class NsfwAndSpoilerFragment extends Fragment {
public static final String EXTRA_ACCOUNT_NAME = "EAN"; public static final String EXTRA_ACCOUNT_NAME = "EAN";
@ -41,6 +41,10 @@ public class NsfwAndBlurringFragment extends Fragment {
LinearLayout blurNsfwLinearLayout; LinearLayout blurNsfwLinearLayout;
@BindView(R.id.blur_nsfw_switch_nsfw_and_spoiler_fragment) @BindView(R.id.blur_nsfw_switch_nsfw_and_spoiler_fragment)
SwitchMaterial blurNsfwSwitchMaterial; SwitchMaterial blurNsfwSwitchMaterial;
@BindView(R.id.do_not_blur_nsfw_in_nsfw_subreddits_linear_layout_nsfw_and_spoiler_fragment)
LinearLayout doNotBlurNsfwInNsfwSubredditsLinearLayout;
@BindView(R.id.do_not_blur_nsfw_in_nsfw_subreddits_switch_nsfw_and_spoiler_fragment)
SwitchMaterial doNotBlurNsfwInNsfwSubredditsSwitch;
@BindView(R.id.blur_spoiler_linear_layout_nsfw_and_spoiler_fragment) @BindView(R.id.blur_spoiler_linear_layout_nsfw_and_spoiler_fragment)
LinearLayout blurSpoilerLinearLayout; LinearLayout blurSpoilerLinearLayout;
@BindView(R.id.blur_spoiler_switch_nsfw_and_spoiler_fragment) @BindView(R.id.blur_spoiler_switch_nsfw_and_spoiler_fragment)
@ -50,8 +54,10 @@ public class NsfwAndBlurringFragment extends Fragment {
SharedPreferences nsfwAndBlurringSharedPreferences; SharedPreferences nsfwAndBlurringSharedPreferences;
private Activity activity; private Activity activity;
private boolean blurNsfw;
private boolean doNotBlurNsfwInNsfwSubreddits;
public NsfwAndBlurringFragment() { public NsfwAndSpoilerFragment() {
// Required empty public constructor // Required empty public constructor
} }
@ -68,15 +74,18 @@ public class NsfwAndBlurringFragment extends Fragment {
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false);
boolean blurNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); blurNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true);
doNotBlurNsfwInNsfwSubreddits = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, false);
boolean blurSpoiler = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); boolean blurSpoiler = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false);
if (enableNsfw) { if (enableNsfw) {
blurNsfwLinearLayout.setVisibility(View.VISIBLE); blurNsfwLinearLayout.setVisibility(View.VISIBLE);
doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.VISIBLE);
} }
enableNsfwSwitchMaterial.setChecked(enableNsfw); enableNsfwSwitchMaterial.setChecked(enableNsfw);
blurNsfwSwitchMaterial.setChecked(blurNsfw); blurNsfwSwitchMaterial.setChecked(blurNsfw);
doNotBlurNsfwInNsfwSubredditsSwitch.setChecked(doNotBlurNsfwInNsfwSubreddits);
blurSpoilerSwitchMaterial.setChecked(blurSpoiler); blurSpoilerSwitchMaterial.setChecked(blurSpoiler);
enableNsfwLinearLayout.setOnClickListener(view -> enableNsfwSwitchMaterial.performClick()); enableNsfwLinearLayout.setOnClickListener(view -> enableNsfwSwitchMaterial.performClick());
@ -84,8 +93,10 @@ public class NsfwAndBlurringFragment extends Fragment {
nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, b).apply(); nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, b).apply();
if (b) { if (b) {
blurNsfwLinearLayout.setVisibility(View.VISIBLE); blurNsfwLinearLayout.setVisibility(View.VISIBLE);
doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.VISIBLE);
} else { } else {
blurNsfwLinearLayout.setVisibility(View.GONE); blurNsfwLinearLayout.setVisibility(View.GONE);
doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.GONE);
} }
EventBus.getDefault().post(new ChangeNSFWEvent(b)); EventBus.getDefault().post(new ChangeNSFWEvent(b));
}); });
@ -93,7 +104,15 @@ public class NsfwAndBlurringFragment extends Fragment {
blurNsfwLinearLayout.setOnClickListener(view -> blurNsfwSwitchMaterial.performClick()); blurNsfwLinearLayout.setOnClickListener(view -> blurNsfwSwitchMaterial.performClick());
blurNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { blurNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> {
nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, b).apply(); nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, b).apply();
EventBus.getDefault().post(new ChangeNSFWBlurEvent(b)); EventBus.getDefault().post(new ChangeNSFWBlurEvent(b, doNotBlurNsfwInNsfwSubreddits));
});
doNotBlurNsfwInNsfwSubredditsLinearLayout.setOnClickListener(view -> {
doNotBlurNsfwInNsfwSubredditsSwitch.performClick();
});
doNotBlurNsfwInNsfwSubredditsSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS, b).apply();
EventBus.getDefault().post(new ChangeNSFWBlurEvent(blurNsfw, b));
}); });
blurSpoilerLinearLayout.setOnClickListener(view -> blurSpoilerSwitchMaterial.performClick()); blurSpoilerLinearLayout.setOnClickListener(view -> blurSpoilerSwitchMaterial.performClick());

View File

@ -274,6 +274,7 @@ public class SharedPreferencesUtils {
public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler"; public static final String NSFW_AND_SPOILER_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.nsfw_and_spoiler";
public static final String NSFW_BASE = "_nsfw"; public static final String NSFW_BASE = "_nsfw";
public static final String BLUR_NSFW_BASE = "_blur_nsfw"; public static final String BLUR_NSFW_BASE = "_blur_nsfw";
public static final String DO_NOT_BLUR_NSFW_IN_NSFW_SUBREDDITS = "do_not_blur_nsfw_in_nsfw_subreddits";
public static final String BLUR_SPOILER_BASE = "_blur_spoiler"; public static final String BLUR_SPOILER_BASE = "_blur_spoiler";
public static final String POST_HISTORY_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_history"; public static final String POST_HISTORY_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_history";

View File

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:orientation="vertical"
tools:context=".settings.NsfwAndBlurringFragment"> tools:context=".settings.NsfwAndSpoilerFragment">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical"
android:animateLayoutChanges="true">
<LinearLayout <LinearLayout
android:id="@+id/enable_nsfw_linear_layout_nsfw_and_spoiler_fragment" android:id="@+id/enable_nsfw_linear_layout_nsfw_and_spoiler_fragment"
@ -77,6 +78,38 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/do_not_blur_nsfw_in_nsfw_subreddits_linear_layout_nsfw_and_spoiler_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingStart="72dp"
android:paddingEnd="16dp"
android:visibility="gone"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="16dp"
android:layout_gravity="center_vertical"
android:text="@string/settings_do_not_blur_nsfw_in_nsfw_subreddits_title"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_16"
android:fontFamily="?attr/font_family" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/do_not_blur_nsfw_in_nsfw_subreddits_switch_nsfw_and_spoiler_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/blur_spoiler_linear_layout_nsfw_and_spoiler_fragment" android:id="@+id/blur_spoiler_linear_layout_nsfw_and_spoiler_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -413,6 +413,7 @@
<string name="settings_enable_nsfw_title">Enable NSFW</string> <string name="settings_enable_nsfw_title">Enable NSFW</string>
<string name="settings_blur_nsfw_title">Blur NSFW Images</string> <string name="settings_blur_nsfw_title">Blur NSFW Images</string>
<string name="settings_blur_spoiler_title">Blur Spoiler Images</string> <string name="settings_blur_spoiler_title">Blur Spoiler Images</string>
<string name="settings_do_not_blur_nsfw_in_nsfw_subreddits_title">Don\'t blur NSFW Images in NSFW Subreddits</string>
<string name="settings_about_master_title">About</string> <string name="settings_about_master_title">About</string>
<string name="settings_acknowledgement_master_title">Acknowledgement</string> <string name="settings_acknowledgement_master_title">Acknowledgement</string>
<string name="settings_credits_master_title">Credits</string> <string name="settings_credits_master_title">Credits</string>

View File

@ -55,7 +55,7 @@
<Preference <Preference
app:icon="@drawable/ic_nsfw_on_24dp" app:icon="@drawable/ic_nsfw_on_24dp"
app:title="@string/settings_nsfw_and_spoiler_title" app:title="@string/settings_nsfw_and_spoiler_title"
app:fragment="ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment"/> app:fragment="ml.docilealligator.infinityforreddit.settings.NsfwAndSpoilerFragment"/>
<Preference <Preference
app:icon="@drawable/ic_history_24dp" app:icon="@drawable/ic_history_24dp"