Mutually exclusive toggling behaviour for DataSavingMode (#603)

Mutually exclusive toggling behavior for DataSavingMode.
This commit is contained in:
scria1000 2021-12-20 13:21:26 +00:00 committed by GitHub
parent a7b58cf0a4
commit 7150ac6981
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,9 +24,33 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW); SwitchPreference disableImagePreviewPreference = findPreference(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW);
SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS); SwitchPreference onlyDisablePreviewInVideoAndGifPostsPreference = findPreference(SharedPreferencesUtils.ONLY_DISABLE_PREVIEW_IN_VIDEO_AND_GIF_POSTS);
if (dataSavingModeListPreference != null) { if (dataSavingModeListPreference != null) {
if (dataSavingModeListPreference.getValue().equals("0")) {
if (onlyDisablePreviewInVideoAndGifPostsPreference != null) {
onlyDisablePreviewInVideoAndGifPostsPreference.setEnabled(false);
}
if (disableImagePreviewPreference != null) {
disableImagePreviewPreference.setEnabled(false);
}
}
dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> { dataSavingModeListPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeDataSavingModeEvent((String) 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; return true;
}); });
} }
@ -34,6 +58,12 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
if (disableImagePreviewPreference != null) { if (disableImagePreviewPreference != null) {
disableImagePreviewPreference.setOnPreferenceChangeListener((preference, newValue) -> { disableImagePreviewPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeDisableImagePreviewEvent((Boolean) 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; return true;
}); });
} }
@ -41,8 +71,14 @@ public class DataSavingModePreferenceFragment extends PreferenceFragmentCompat {
if (onlyDisablePreviewInVideoAndGifPostsPreference != null) { if (onlyDisablePreviewInVideoAndGifPostsPreference != null) {
onlyDisablePreviewInVideoAndGifPostsPreference.setOnPreferenceChangeListener((preference, newValue) -> { onlyDisablePreviewInVideoAndGifPostsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeOnlyDisablePreviewInVideoAndGifPostsEvent((Boolean) 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; return true;
}); });
} }
} }
} }