From 6beb4485401a4da1a22a86f062f359d2c01bf3ef Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 12 Mar 2021 11:43:44 +0800 Subject: New option: Do not blur nsfw media in nsfw subreddits. --- .../infinityforreddit/AppComponent.java | 4 +- .../activities/LinkResolverActivity.java | 3 +- .../activities/SettingsActivity.java | 6 +- .../activities/ViewPostDetailActivity.java | 8 ++ .../activities/ViewSubredditDetailActivity.java | 7 ++ .../CommentAndPostRecyclerViewAdapter.java | 15 ++- .../adapters/PostRecyclerViewAdapter.java | 20 ++-- .../events/ChangeNSFWBlurEvent.java | 4 +- .../infinityforreddit/fragments/PostFragment.java | 11 +- .../fragments/ViewPostDetailFragment.java | 9 +- .../settings/NsfwAndBlurringFragment.java | 112 ------------------ .../settings/NsfwAndSpoilerFragment.java | 131 +++++++++++++++++++++ .../utils/SharedPreferencesUtils.java | 1 + 13 files changed, 196 insertions(+), 135 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndBlurringFragment.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 8fa5d081..4af5a6c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -80,7 +80,7 @@ import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenc import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment; 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.SecurityPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.ThemePreferenceFragment; @@ -224,7 +224,7 @@ public interface AppComponent { void inject(SecurityPreferenceFragment securityPreferenceFragment); - void inject(NsfwAndBlurringFragment nsfwAndBlurringFragment); + void inject(NsfwAndSpoilerFragment nsfwAndSpoilerFragment); void inject(CustomizeBottomAppBarFragment customizeBottomAppBarFragment); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java index 5e536223..0ba911c8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LinkResolverActivity.java @@ -32,6 +32,7 @@ public class LinkResolverActivity extends AppCompatActivity { 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_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 SUBREDDIT_PATTERN = "/[rR]/[\\w-]+/?"; private static final String USER_PATTERN = "/(u|U|user)/[\\w-]+/?"; @@ -125,7 +126,7 @@ public class LinkResolverActivity extends AppCompatActivity { } else if (path.isEmpty()) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); - } else if (path.matches(POST_PATTERN)) { + } else if (path.matches(POST_PATTERN) || path.matches(POST_PATTERN_2)) { int commentsIndex = segments.lastIndexOf("comments"); if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { Intent intent = new Intent(this, ViewPostDetailActivity.class); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java index e19b5fa9..c1183636 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java @@ -33,7 +33,7 @@ import ml.docilealligator.infinityforreddit.settings.FontPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenceFragment; import ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment; 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.utils.SharedPreferencesUtils; @@ -155,8 +155,8 @@ public class SettingsActivity extends BaseActivity implements pref.getFragment()); if (fragment instanceof CustomizeMainPageTabsFragment) { args.putString(CustomizeMainPageTabsFragment.EXTRA_ACCOUNT_NAME, mAccountName); - } else if (fragment instanceof NsfwAndBlurringFragment) { - args.putString(NsfwAndBlurringFragment.EXTRA_ACCOUNT_NAME, mAccountName); + } else if (fragment instanceof NsfwAndSpoilerFragment) { + args.putString(NsfwAndSpoilerFragment.EXTRA_ACCOUNT_NAME, mAccountName); } else if (fragment instanceof CustomizeBottomAppBarFragment) { args.putString(CustomizeBottomAppBarFragment.EXTRA_ACCOUNT_NAME, mAccountName); } else if (fragment instanceof PostHistoryFragment) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java index 078d782f..4577cb96 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewPostDetailActivity.java @@ -69,6 +69,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele public static final String EXTRA_MESSAGE_FULLNAME = "ENI"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; 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 GIVE_AWARD_REQUEST_CODE = 100; @State @@ -108,6 +109,7 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele private int postListPosition = -1; private int orientation; private boolean mVolumeKeysNavigateComments; + private boolean isNsfwSubreddit; @Override @@ -163,6 +165,8 @@ public class ViewPostDetailActivity extends BaseActivity implements SortTypeSele EventBus.getDefault().post(new NeedForPostListFromPostFragmentEvent(postFragmentId)); } + isNsfwSubreddit = getIntent().getBooleanExtra(EXTRA_IS_NSFW_SUBREDDIT, false); + fragmentManager = getSupportFragmentManager(); 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) { if (sectionsPagerAdapter != null) { ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 15c0071d..e0a9ab7a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -201,6 +201,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp private String subredditName; private boolean mFetchSubredditInfoSuccess = false; private int mNCurrentOnlineSubscribers = 0; + private boolean isNsfwSubreddit = false; private boolean subscriptionReady = false; private boolean isInLazyMode = false; private boolean showToast = false; @@ -364,6 +365,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp .get(SubredditViewModel.class); mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> { if (subredditData != null) { + isNsfwSubreddit = subredditData.isNSFW(); + if (subredditData.getBannerUrl().equals("")) { iconGifImageView.setOnClickListener(view -> { //Do nothing as it has no image @@ -1111,6 +1114,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp EventBus.getDefault().unregister(this); } + public boolean isNsfwSubreddit() { + return isNsfwSubreddit; + } + private void makeSnackbar(int resId, boolean retry) { if (showToast) { Toast.makeText(this, resId, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index bfa2e0b1..8b779730 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -164,6 +164,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { @@ -1571,7 +1573,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter preview.getPreviewWidth()) { @@ -1870,8 +1872,9 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter posts = mAdapter.getCurrentList(); @@ -1522,7 +1531,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Subscribe public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { if (mAdapter != null) { - mAdapter.setBlurNSFW(event.needBlurNSFW); + mAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits); refreshAdapter(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java index 97d55b66..e9fb018c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewPostDetailFragment.java @@ -1664,6 +1664,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic }); } + public boolean getIsNsfwSubreddit() { + if (activity != null) { + return activity.isNsfwSubreddit(); + } + return false; + } + @Subscribe public void onPostUpdateEvent(PostUpdateEventToDetailActivity event) { if (mPost.getId().equals(event.post.getId())) { @@ -1682,7 +1689,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic @Subscribe public void onChangeNSFWBlurEvent(ChangeNSFWBlurEvent event) { - mAdapter.setBlurNSFW(event.needBlurNSFW); + mAdapter.setBlurNsfwAndDoNotBlurNsfwInNsfwSubreddits(event.needBlurNSFW, event.doNotBlurNsfwInNsfwSubreddits); refreshAdapter(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndBlurringFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndBlurringFragment.java deleted file mode 100644 index a4373a70..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndBlurringFragment.java +++ /dev/null @@ -1,112 +0,0 @@ -package ml.docilealligator.infinityforreddit.settings; - -import android.app.Activity; -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; - -import com.google.android.material.switchmaterial.SwitchMaterial; - -import org.greenrobot.eventbus.EventBus; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; -import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; -import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; - -public class NsfwAndBlurringFragment extends Fragment { - - public static final String EXTRA_ACCOUNT_NAME = "EAN"; - - @BindView(R.id.enable_nsfw_linear_layout_nsfw_and_spoiler_fragment) - LinearLayout enableNsfwLinearLayout; - @BindView(R.id.enable_nsfw_switch_nsfw_and_spoiler_fragment) - SwitchMaterial enableNsfwSwitchMaterial; - @BindView(R.id.blur_nsfw_linear_layout_nsfw_and_spoiler_fragment) - LinearLayout blurNsfwLinearLayout; - @BindView(R.id.blur_nsfw_switch_nsfw_and_spoiler_fragment) - SwitchMaterial blurNsfwSwitchMaterial; - @BindView(R.id.blur_spoiler_linear_layout_nsfw_and_spoiler_fragment) - LinearLayout blurSpoilerLinearLayout; - @BindView(R.id.blur_spoiler_switch_nsfw_and_spoiler_fragment) - SwitchMaterial blurSpoilerSwitchMaterial; - @Inject - @Named("nsfw_and_spoiler") - SharedPreferences nsfwAndBlurringSharedPreferences; - - private Activity activity; - - public NsfwAndBlurringFragment() { - // Required empty public constructor - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_nsfw_and_spoiler, container, false); - - ((Infinity) activity.getApplication()).getAppComponent().inject(this); - - ButterKnife.bind(this, rootView); - - String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); - - boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); - boolean blurNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, true); - boolean blurSpoiler = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, false); - - if (enableNsfw) { - blurNsfwLinearLayout.setVisibility(View.VISIBLE); - } - - enableNsfwSwitchMaterial.setChecked(enableNsfw); - blurNsfwSwitchMaterial.setChecked(blurNsfw); - blurSpoilerSwitchMaterial.setChecked(blurSpoiler); - - enableNsfwLinearLayout.setOnClickListener(view -> enableNsfwSwitchMaterial.performClick()); - enableNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { - nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, b).apply(); - if (b) { - blurNsfwLinearLayout.setVisibility(View.VISIBLE); - } else { - blurNsfwLinearLayout.setVisibility(View.GONE); - } - EventBus.getDefault().post(new ChangeNSFWEvent(b)); - }); - - blurNsfwLinearLayout.setOnClickListener(view -> blurNsfwSwitchMaterial.performClick()); - blurNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { - nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, b).apply(); - EventBus.getDefault().post(new ChangeNSFWBlurEvent(b)); - }); - - blurSpoilerLinearLayout.setOnClickListener(view -> blurSpoilerSwitchMaterial.performClick()); - blurSpoilerSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { - nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, b).apply(); - EventBus.getDefault().post(new ChangeSpoilerBlurEvent(b)); - }); - return rootView; - } - - @Override - public void onAttach(@NonNull Context context) { - super.onAttach(context); - this.activity = (AppCompatActivity) context; - } -} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java new file mode 100644 index 00000000..99affad3 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/NsfwAndSpoilerFragment.java @@ -0,0 +1,131 @@ +package ml.docilealligator.infinityforreddit.settings; + +import android.app.Activity; +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.Fragment; + +import com.google.android.material.switchmaterial.SwitchMaterial; + +import org.greenrobot.eventbus.EventBus; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent; +import ml.docilealligator.infinityforreddit.events.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class NsfwAndSpoilerFragment extends Fragment { + + public static final String EXTRA_ACCOUNT_NAME = "EAN"; + + @BindView(R.id.enable_nsfw_linear_layout_nsfw_and_spoiler_fragment) + LinearLayout enableNsfwLinearLayout; + @BindView(R.id.enable_nsfw_switch_nsfw_and_spoiler_fragment) + SwitchMaterial enableNsfwSwitchMaterial; + @BindView(R.id.blur_nsfw_linear_layout_nsfw_and_spoiler_fragment) + LinearLayout blurNsfwLinearLayout; + @BindView(R.id.blur_nsfw_switch_nsfw_and_spoiler_fragment) + 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) + LinearLayout blurSpoilerLinearLayout; + @BindView(R.id.blur_spoiler_switch_nsfw_and_spoiler_fragment) + SwitchMaterial blurSpoilerSwitchMaterial; + @Inject + @Named("nsfw_and_spoiler") + SharedPreferences nsfwAndBlurringSharedPreferences; + + private Activity activity; + private boolean blurNsfw; + private boolean doNotBlurNsfwInNsfwSubreddits; + + public NsfwAndSpoilerFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_nsfw_and_spoiler, container, false); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + ButterKnife.bind(this, rootView); + + String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME); + + boolean enableNsfw = nsfwAndBlurringSharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, false); + 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); + + if (enableNsfw) { + blurNsfwLinearLayout.setVisibility(View.VISIBLE); + doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.VISIBLE); + } + + enableNsfwSwitchMaterial.setChecked(enableNsfw); + blurNsfwSwitchMaterial.setChecked(blurNsfw); + doNotBlurNsfwInNsfwSubredditsSwitch.setChecked(doNotBlurNsfwInNsfwSubreddits); + blurSpoilerSwitchMaterial.setChecked(blurSpoiler); + + enableNsfwLinearLayout.setOnClickListener(view -> enableNsfwSwitchMaterial.performClick()); + enableNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.NSFW_BASE, b).apply(); + if (b) { + blurNsfwLinearLayout.setVisibility(View.VISIBLE); + doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.VISIBLE); + } else { + blurNsfwLinearLayout.setVisibility(View.GONE); + doNotBlurNsfwInNsfwSubredditsLinearLayout.setVisibility(View.GONE); + } + EventBus.getDefault().post(new ChangeNSFWEvent(b)); + }); + + blurNsfwLinearLayout.setOnClickListener(view -> blurNsfwSwitchMaterial.performClick()); + blurNsfwSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_NSFW_BASE, b).apply(); + 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()); + blurSpoilerSwitchMaterial.setOnCheckedChangeListener((compoundButton, b) -> { + nsfwAndBlurringSharedPreferences.edit().putBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.BLUR_SPOILER_BASE, b).apply(); + EventBus.getDefault().post(new ChangeSpoilerBlurEvent(b)); + }); + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + this.activity = (AppCompatActivity) context; + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index e1089706..1d2ba964 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -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_BASE = "_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 POST_HISTORY_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_history"; -- cgit v1.2.3