From 7150ac69815a34011a3c92f2adf75baa5bf76c65 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Mon, 20 Dec 2021 13:21:26 +0000 Subject: Mutually exclusive toggling behaviour for DataSavingMode (#603) Mutually exclusive toggling behavior for DataSavingMode. --- .../settings/DataSavingModePreferenceFragment.java | 38 +++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java index 84377724..915438a6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/DataSavingModePreferenceFragment.java @@ -24,9 +24,33 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW); SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS); + if (dataSavingModeListPreference != null) { + if (dataSavingModeListPreference.getValue().equals("0")) { + if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { + onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(false); + } + if (disableImagePreviewPreference != null) { + disableImagePreviewPreference.setEnabled(false); + } + } dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeDataSavingModeEvent((String) newValue)); + if (newValue.equals("0")) { + if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { + onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(false); + } + if (disableImagePreviewPreference != null) { + disableImagePreviewPreference.setEnabled(false); + } + } else { + if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { + onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(true); + } + if (disableImagePreviewPreference != null) { + disableImagePreviewPreference.setEnabled(true); + } + } return true; }); } @@ -34,6 +58,12 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { if (disableImagePreviewPreference != null) { disableImagePreviewPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeDisableImagePreviewEvent((Boolean) newValue)); + if ((Boolean) newValue) { + EventBus.getDefault().post(new ChangeOnlyDisablePreviewInVideoAndGifPostsEvent(false)); + if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { + onlyDisablePreviewInVideoAndGifPostsPreference.setChecked(false); + } + } return true; }); } @@ -41,8 +71,14 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat { if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { onlyDisablePreviewInVideoAndGifPostsPreference.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeOnlyDisablePreviewInVideoAndGifPostsEvent((Boolean) newValue)); + if ((Boolean) newValue) { + EventBus.getDefault().post(new ChangeDisableImagePreviewEvent(false)); + if (disableImagePreviewPreference != null) { + disableImagePreviewPreference.setChecked(false); + } + } return true; }); } } -} \ No newline at end of file +} -- cgit v1.2.3