From 837e461451a877c581ea38e401863a266a1781ca Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 27 Sep 2019 00:30:24 +0800 Subject: Add title and content font size options. --- .../java/Settings/FontSizePreferenceFragment.java | 49 ++++++++++++++++++++++ .../main/java/Settings/MainPreferenceFragment.java | 10 ----- 2 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/Settings/FontSizePreferenceFragment.java (limited to 'app/src/main/java/Settings') diff --git a/app/src/main/java/Settings/FontSizePreferenceFragment.java b/app/src/main/java/Settings/FontSizePreferenceFragment.java new file mode 100644 index 00000000..41000a5a --- /dev/null +++ b/app/src/main/java/Settings/FontSizePreferenceFragment.java @@ -0,0 +1,49 @@ +package Settings; + +import android.app.Activity; +import android.os.Bundle; + +import androidx.preference.ListPreference; +import androidx.preference.PreferenceFragmentCompat; + +import org.greenrobot.eventbus.EventBus; + +import ml.docilealligator.infinityforreddit.ChangeFontSizeEvent; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; + +public class FontSizePreferenceFragment extends PreferenceFragmentCompat { + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.font_size_preferences, rootKey); + + Activity activity = getActivity(); + if(activity != null) { + ListPreference fontSizePreference = findPreference(SharedPreferencesUtils.FONT_SIZE_KEY); + ListPreference titleFontSizePreference = findPreference(SharedPreferencesUtils.TITLE_FONT_SIZE_KEY); + ListPreference contentFontSizePreference = findPreference(SharedPreferencesUtils.CONTENT_FONT_SIZE_KEY); + + if(fontSizePreference != null) { + fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeFontSizeEvent()); + activity.recreate(); + return true; + }); + } + + if(titleFontSizePreference != null) { + titleFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeFontSizeEvent()); + return true; + }); + } + + if(contentFontSizePreference != null) { + contentFontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeFontSizeEvent()); + return true; + }); + } + } + } +} diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java index 847112a9..af498294 100644 --- a/app/src/main/java/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/Settings/MainPreferenceFragment.java @@ -15,7 +15,6 @@ import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; -import ml.docilealligator.infinityforreddit.ChangeFontSizeEvent; import ml.docilealligator.infinityforreddit.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Infinity; @@ -46,7 +45,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY); - ListPreference fontSizePreference = findPreference(SharedPreferencesUtils.FONT_SIZE_KEY); if(nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { @@ -101,14 +99,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { return true; }); } - - if(fontSizePreference != null) { - fontSizePreference.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new ChangeFontSizeEvent((String) newValue)); - activity.recreate(); - return true; - }); - } } } } -- cgit v1.2.3