From 256302e914d7ee038fb4be76bd2b8883f3e1f841 Mon Sep 17 00:00:00 2001 From: Joey Peter Date: Sun, 31 Jul 2022 21:21:19 +0200 Subject: [PATCH] fix: `sponsorblock` settings not getting saved (#112) --- .../integrations/settings/SettingsEnum.java | 4 ++-- .../settingsmenu/ReVancedSettingActivity.java | 17 +---------------- .../SponsorBlockSettingsFragment.java | 6 ++++++ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java index 9741aa6b..439b38db 100644 --- a/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java +++ b/app/src/main/java/app/revanced/integrations/settings/SettingsEnum.java @@ -96,8 +96,8 @@ public enum SettingsEnum { SB_ADJUST_NEW_SEGMENT_STEP("new-segment-step-accuracy", 150, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.INTEGER), SB_MIN_DURATION("sb-min-duration", 0F, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.FLOAT), SB_SEEN_GUIDELINES("sb-seen-gl", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), - SB_NEW_SEGMENT_ENABLED("sb-new-segment-enabled", true, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), - SB_VOTING_ENABLED("sb-voting-enabled", true, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), + SB_NEW_SEGMENT_ENABLED("sb-new-segment-enabled", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), + SB_VOTING_ENABLED("sb-voting-enabled", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), SB_SKIPPED_SEGMENTS("sb-skipped-segments", 0, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.INTEGER), SB_SKIPPED_SEGMENTS_TIME("sb-skipped-segments-time", 0L, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.LONG), SB_SHOW_TIME_WITHOUT_SEGMENTS("sb-length-without-segments", true, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), diff --git a/app/src/main/java/app/revanced/integrations/settingsmenu/ReVancedSettingActivity.java b/app/src/main/java/app/revanced/integrations/settingsmenu/ReVancedSettingActivity.java index 31754d91..88874dde 100644 --- a/app/src/main/java/app/revanced/integrations/settingsmenu/ReVancedSettingActivity.java +++ b/app/src/main/java/app/revanced/integrations/settingsmenu/ReVancedSettingActivity.java @@ -28,14 +28,6 @@ public class ReVancedSettingActivity { public static void initializeSettings(LicenseActivity base) { base.setContentView(getIdentifier("xsettings_with_toolbar", "layout")); - try { - ImageButton imageButton = getImageButton(base.findViewById(getIdentifier("toolbar", "id"))); - imageButton.setOnClickListener(view -> base.onBackPressed()); - imageButton.setImageDrawable(base.getResources().getDrawable(getIdentifier(ThemeHelper.isDarkTheme() ? "quantum_ic_arrow_back_white_24" : "quantum_ic_arrow_back_grey600_24", "drawable"), null)); - } catch (Exception e) { - LogHelper.printException(ReVancedSettingActivity.class, "Couldn't set Toolbar click handler", e); - } - PreferenceFragment preferenceFragment; String preferenceIdentifier; @@ -50,14 +42,7 @@ public class ReVancedSettingActivity { preferenceIdentifier = "revanced_settings"; preferenceFragment = new ReVancedSettingsFragment(); } - - try { - var resourceIdentifier = getIdentifier(preferenceIdentifier, "string"); - getTextView(base.findViewById(getIdentifier("toolbar", "id"))).setText(resourceIdentifier); - } catch (Exception e) { - LogHelper.printException(ReVancedSettingActivity.class, "Couldn't set Toolbar title", e); - } - + base.getFragmentManager().beginTransaction().replace(getIdentifier("xsettings_fragments", "id"), preferenceFragment).commit(); } diff --git a/app/src/main/java/app/revanced/integrations/settingsmenu/SponsorBlockSettingsFragment.java b/app/src/main/java/app/revanced/integrations/settingsmenu/SponsorBlockSettingsFragment.java index bff7586a..4b4829a8 100644 --- a/app/src/main/java/app/revanced/integrations/settingsmenu/SponsorBlockSettingsFragment.java +++ b/app/src/main/java/app/revanced/integrations/settingsmenu/SponsorBlockSettingsFragment.java @@ -90,6 +90,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements .setPositiveButton(str("sb_guidelines_popup_open"), (dialogInterface, i) -> openGuidelines()) .show(); } + SettingsEnum.SB_NEW_SEGMENT_ENABLED.saveValue(value); return true; }); } @@ -103,6 +104,11 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements preference.setDefaultValue(SettingsEnum.SB_VOTING_ENABLED.getDefaultValue()); preference.setChecked(SettingsEnum.SB_VOTING_ENABLED.getBoolean()); preferencesToDisableWhenSBDisabled.add(preference); + preference.setOnPreferenceChangeListener((preference12, o) -> { + final boolean value = (Boolean) o; + SettingsEnum.SB_VOTING_ENABLED.saveValue(value); + return true; + }); } addGeneralCategory(context, preferenceScreen);