aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/Settings/MainPreferenceFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/Settings/MainPreferenceFragment.java')
-rw-r--r--app/src/main/java/Settings/MainPreferenceFragment.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java
index 69b688b2..db098503 100644
--- a/app/src/main/java/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/Settings/MainPreferenceFragment.java
@@ -4,8 +4,13 @@ package Settings;
import android.os.Bundle;
import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.SwitchPreference;
+import org.greenrobot.eventbus.EventBus;
+
+import ml.docilealligator.infinityforreddit.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
/**
* A simple {@link PreferenceFragmentCompat} subclass.
@@ -14,5 +19,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.main_preferences, rootKey);
+
+ SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
+ if(nsfwSwitch != null) {
+ nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
+ return true;
+ });
+ }
}
}