aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/Settings/MainPreferenceFragment.java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-09-17 07:04:37 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-09-17 07:04:37 +0000
commitee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd (patch)
tree70eef13261988a993f4324d7e2cc17ba74d8e618 /app/src/main/java/Settings/MainPreferenceFragment.java
parent3592dc29dabe1fbc41f4af5536e395987963c810 (diff)
downloadinfinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar.gz
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar.bz2
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar.lz
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar.xz
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.tar.zst
infinity-for-reddit-ee5fc0a5fc652c9e0b83b4f82ec80f1ec81380fd.zip
Unbluring NSFW images is now an option in settings.
Diffstat (limited to 'app/src/main/java/Settings/MainPreferenceFragment.java')
-rw-r--r--app/src/main/java/Settings/MainPreferenceFragment.java95
1 files changed, 64 insertions, 31 deletions
diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java
index fbe97347..11093bf6 100644
--- a/app/src/main/java/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/Settings/MainPreferenceFragment.java
@@ -1,6 +1,8 @@
package Settings;
+import android.app.Activity;
+import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
@@ -11,7 +13,11 @@ import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
+import javax.inject.Inject;
+
+import ml.docilealligator.infinityforreddit.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.ChangeNSFWEvent;
+import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
@@ -25,47 +31,74 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
*/
public class MainPreferenceFragment extends PreferenceFragmentCompat {
+ @Inject
+ SharedPreferences sharedPreferences;
+
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.main_preferences, rootKey);
- SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
- ListPreference listPreference = findPreference(SharedPreferencesUtils.THEME_KEY);
+ Activity activity = getActivity();
+ if(activity != null) {
+ ((Infinity) activity.getApplication()).getAppComponent().inject(this);
- if(nsfwSwitch != null) {
- nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
- EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
- return true;
- });
- }
+ SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
+ SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
+ ListPreference listPreference = findPreference(SharedPreferencesUtils.THEME_KEY);
+
+ if(nsfwSwitch != null) {
+ nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));
+ if(blurNSFWSwitch != null) {
+ blurNSFWSwitch.setVisible((Boolean) newValue);
+ }
+ return true;
+ });
+ }
- boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
+ if(blurNSFWSwitch != null) {
+ boolean nsfwEnabled = sharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
- if(listPreference != null) {
- if(systemDefault) {
- listPreference.setEntries(R.array.settings_theme_q);
- } else {
- listPreference.setEntries(R.array.settings_theme);
+ if(nsfwEnabled) {
+ blurNSFWSwitch.setVisible(true);
+ } else {
+ blurNSFWSwitch.setVisible(false);
+ }
+
+ blurNSFWSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ EventBus.getDefault().post(new ChangeNSFWBlurEvent((Boolean) newValue));
+ return true;
+ });
}
- listPreference.setOnPreferenceChangeListener((preference, newValue) -> {
- int option = Integer.parseInt((String) newValue);
- switch (option) {
- case 0:
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
- break;
- case 1:
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
- break;
- case 2:
- if(systemDefault) {
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
- } else {
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
- }
+ boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
+
+ if(listPreference != null) {
+ if(systemDefault) {
+ listPreference.setEntries(R.array.settings_theme_q);
+ } else {
+ listPreference.setEntries(R.array.settings_theme);
}
- return true;
- });
+
+ listPreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ int option = Integer.parseInt((String) newValue);
+ switch (option) {
+ case 0:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
+ break;
+ case 1:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
+ break;
+ case 2:
+ if(systemDefault) {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
+ }
+ }
+ return true;
+ });
+ }
}
}
}