Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

Commit 8e59705

Browse files
committed
fix(YouTube/SponsorBlock): wrong segment behavior selected inotia00/ReVanced_Extended#2468
1 parent 9b74474 commit 8e59705

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

app/src/main/java/app/revanced/integrations/youtube/settings/preference/ReVancedPreferenceFragment.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
8080

8181
if (mPreference == null) return;
8282

83-
if (mPreference instanceof app.revanced.integrations.youtube.settings.preference.SegmentCategoryListPreference) {
84-
return;
85-
}
86-
8783
if (mPreference instanceof SwitchPreference switchPreference) {
8884
BooleanSetting boolSetting = (BooleanSetting) setting;
8985
if (settingImportInProgress) {
@@ -109,12 +105,13 @@ public class ReVancedPreferenceFragment extends PreferenceFragment {
109105
} else {
110106
Setting.privateSetValueFromString(setting, listPreference.getValue());
111107
}
112-
113108
if (setting.equals(DEFAULT_PLAYBACK_SPEED)) {
114109
listPreference.setEntries(CustomPlaybackSpeedPatch.getListEntries());
115110
listPreference.setEntryValues(CustomPlaybackSpeedPatch.getListEntryValues());
116111
}
117-
updateListPreferenceSummary(listPreference, setting);
112+
if (!(mPreference instanceof app.revanced.integrations.youtube.settings.preference.SegmentCategoryListPreference)) {
113+
updateListPreferenceSummary(listPreference, setting);
114+
}
118115
} else {
119116
Logger.printException(() -> "Setting cannot be handled: " + mPreference.getClass() + " " + mPreference);
120117
return;
@@ -276,7 +273,9 @@ public void onCreate(Bundle bundle) {
276273
listPreference.setEntries(CustomPlaybackSpeedPatch.getListEntries());
277274
listPreference.setEntryValues(CustomPlaybackSpeedPatch.getListEntryValues());
278275
}
279-
updateListPreferenceSummary(listPreference, setting);
276+
if (!(preference instanceof app.revanced.integrations.youtube.settings.preference.SegmentCategoryListPreference)) {
277+
updateListPreferenceSummary(listPreference, setting);
278+
}
280279
}
281280
}
282281

app/src/main/java/app/revanced/integrations/youtube/settings/preference/SegmentCategoryListPreference.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ private void init() {
3535
final SegmentCategory segmentCategory = SegmentCategory.byCategoryKey(getKey());
3636
final boolean isHighlightCategory = segmentCategory == SegmentCategory.HIGHLIGHT;
3737
mCategory = Objects.requireNonNull(segmentCategory);
38-
setDefaultValue(segmentCategory.behaviour.reVancedKeyValue);
38+
// Edit: Using preferences to sync together multiple pieces
39+
// of code together is messy and should be rethought.
40+
setKey(segmentCategory.behaviorSetting.key);
41+
setDefaultValue(segmentCategory.behaviorSetting.defaultValue);
42+
3943
setEntries(isHighlightCategory
4044
? CategoryBehaviour.getBehaviorDescriptionsWithoutSkipOnce()
4145
: CategoryBehaviour.getBehaviorDescriptions());
4246
setEntryValues(isHighlightCategory
4347
? CategoryBehaviour.getBehaviorKeyValuesWithoutSkipOnce()
4448
: CategoryBehaviour.getBehaviorKeyValues());
45-
setSummary(segmentCategory.description.toString());
4649
updateTitle();
4750
}
4851

@@ -137,7 +140,6 @@ public void afterTextChanged(Editable s) {
137140
}
138141
});
139142
builder.setNegativeButton(android.R.string.cancel, null);
140-
141143
mClickedDialogEntryIndex = findIndexOfValue(getValue());
142144
builder.setSingleChoiceItems(getEntries(), mClickedDialogEntryIndex, (dialog, which) -> mClickedDialogEntryIndex = which);
143145
} catch (Exception ex) {

app/src/main/java/app/revanced/integrations/youtube/sponsorblock/objects/SegmentCategory.java

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,34 @@
4343
import app.revanced.integrations.shared.utils.Utils;
4444
import app.revanced.integrations.youtube.settings.Settings;
4545

46-
/**
47-
* @noinspection deprecation
48-
*/
46+
@SuppressWarnings({"deprecation", "StaticFieldLeak"})
4947
public enum SegmentCategory {
50-
SPONSOR("sponsor", sf("revanced_sb_segments_sponsor"), sf("revanced_sb_segments_sponsor_sum"), sf("revanced_sb_skip_button_sponsor"), sf("revanced_sb_skipped_sponsor"),
48+
SPONSOR("sponsor", sf("revanced_sb_segments_sponsor"), sf("revanced_sb_skip_button_sponsor"), sf("revanced_sb_skipped_sponsor"),
5149
SB_CATEGORY_SPONSOR, SB_CATEGORY_SPONSOR_COLOR),
52-
SELF_PROMO("selfpromo", sf("revanced_sb_segments_selfpromo"), sf("revanced_sb_segments_selfpromo_sum"), sf("revanced_sb_skip_button_selfpromo"), sf("revanced_sb_skipped_selfpromo"),
50+
SELF_PROMO("selfpromo", sf("revanced_sb_segments_selfpromo"), sf("revanced_sb_skip_button_selfpromo"), sf("revanced_sb_skipped_selfpromo"),
5351
SB_CATEGORY_SELF_PROMO, SB_CATEGORY_SELF_PROMO_COLOR),
54-
INTERACTION("interaction", sf("revanced_sb_segments_interaction"), sf("revanced_sb_segments_interaction_sum"), sf("revanced_sb_skip_button_interaction"), sf("revanced_sb_skipped_interaction"),
52+
INTERACTION("interaction", sf("revanced_sb_segments_interaction"), sf("revanced_sb_skip_button_interaction"), sf("revanced_sb_skipped_interaction"),
5553
SB_CATEGORY_INTERACTION, SB_CATEGORY_INTERACTION_COLOR),
5654
/**
5755
* Unique category that is treated differently than the rest.
5856
*/
59-
HIGHLIGHT("poi_highlight", sf("revanced_sb_segments_highlight"), sf("revanced_sb_segments_highlight_sum"), sf("revanced_sb_skip_button_highlight"), sf("revanced_sb_skipped_highlight"),
57+
HIGHLIGHT("poi_highlight", sf("revanced_sb_segments_highlight"), sf("revanced_sb_skip_button_highlight"), sf("revanced_sb_skipped_highlight"),
6058
SB_CATEGORY_HIGHLIGHT, SB_CATEGORY_HIGHLIGHT_COLOR),
61-
INTRO("intro", sf("revanced_sb_segments_intro"), sf("revanced_sb_segments_intro_sum"),
59+
INTRO("intro", sf("revanced_sb_segments_intro"),
6260
sf("revanced_sb_skip_button_intro_beginning"), sf("revanced_sb_skip_button_intro_middle"), sf("revanced_sb_skip_button_intro_end"),
6361
sf("revanced_sb_skipped_intro_beginning"), sf("revanced_sb_skipped_intro_middle"), sf("revanced_sb_skipped_intro_end"),
6462
SB_CATEGORY_INTRO, SB_CATEGORY_INTRO_COLOR),
65-
OUTRO("outro", sf("revanced_sb_segments_outro"), sf("revanced_sb_segments_outro_sum"), sf("revanced_sb_skip_button_outro"), sf("revanced_sb_skipped_outro"),
63+
OUTRO("outro", sf("revanced_sb_segments_outro"), sf("revanced_sb_skip_button_outro"), sf("revanced_sb_skipped_outro"),
6664
SB_CATEGORY_OUTRO, SB_CATEGORY_OUTRO_COLOR),
67-
PREVIEW("preview", sf("revanced_sb_segments_preview"), sf("revanced_sb_segments_preview_sum"),
65+
PREVIEW("preview", sf("revanced_sb_segments_preview"),
6866
sf("revanced_sb_skip_button_preview_beginning"), sf("revanced_sb_skip_button_preview_middle"), sf("revanced_sb_skip_button_preview_end"),
6967
sf("revanced_sb_skipped_preview_beginning"), sf("revanced_sb_skipped_preview_middle"), sf("revanced_sb_skipped_preview_end"),
7068
SB_CATEGORY_PREVIEW, SB_CATEGORY_PREVIEW_COLOR),
71-
FILLER("filler", sf("revanced_sb_segments_filler"), sf("revanced_sb_segments_filler_sum"), sf("revanced_sb_skip_button_filler"), sf("revanced_sb_skipped_filler"),
69+
FILLER("filler", sf("revanced_sb_segments_filler"), sf("revanced_sb_skip_button_filler"), sf("revanced_sb_skipped_filler"),
7270
SB_CATEGORY_FILLER, SB_CATEGORY_FILLER_COLOR),
73-
MUSIC_OFFTOPIC("music_offtopic", sf("revanced_sb_segments_nomusic"), sf("revanced_sb_segments_nomusic_sum"), sf("revanced_sb_skip_button_nomusic"), sf("revanced_sb_skipped_nomusic"),
71+
MUSIC_OFFTOPIC("music_offtopic", sf("revanced_sb_segments_nomusic"), sf("revanced_sb_skip_button_nomusic"), sf("revanced_sb_skipped_nomusic"),
7472
SB_CATEGORY_MUSIC_OFFTOPIC, SB_CATEGORY_MUSIC_OFFTOPIC_COLOR),
75-
UNSUBMITTED("unsubmitted", StringRef.empty, StringRef.empty, sf("revanced_sb_skip_button_unsubmitted"), sf("revanced_sb_skipped_unsubmitted"),
73+
UNSUBMITTED("unsubmitted", StringRef.empty, sf("revanced_sb_skip_button_unsubmitted"), sf("revanced_sb_skipped_unsubmitted"),
7674
SB_CATEGORY_UNSUBMITTED, SB_CATEGORY_UNSUBMITTED_COLOR),
7775
;
7876

@@ -159,14 +157,12 @@ public static void loadAllCategoriesFromSettings() {
159157
@NonNull
160158
public final String keyValue;
161159
@NonNull
162-
private final StringSetting behaviorSetting;
160+
public final StringSetting behaviorSetting;
163161
@NonNull
164162
private final StringSetting colorSetting;
165163

166164
@NonNull
167165
public final StringRef title;
168-
@NonNull
169-
public final StringRef description;
170166

171167
/**
172168
* Skip button text, if the skip occurs in the first quarter of the video
@@ -214,23 +210,22 @@ public static void loadAllCategoriesFromSettings() {
214210
@NonNull
215211
public CategoryBehaviour behaviour = CategoryBehaviour.IGNORE;
216212

217-
SegmentCategory(String keyValue, StringRef title, StringRef description,
213+
SegmentCategory(String keyValue, StringRef title,
218214
StringRef skipButtonText,
219215
StringRef skippedToastText,
220216
StringSetting behavior, StringSetting color) {
221-
this(keyValue, title, description,
217+
this(keyValue, title,
222218
skipButtonText, skipButtonText, skipButtonText,
223219
skippedToastText, skippedToastText, skippedToastText,
224220
behavior, color);
225221
}
226222

227-
SegmentCategory(String keyValue, StringRef title, StringRef description,
223+
SegmentCategory(String keyValue, StringRef title,
228224
StringRef skipButtonTextBeginning, StringRef skipButtonTextMiddle, StringRef skipButtonTextEnd,
229225
StringRef skippedToastBeginning, StringRef skippedToastMiddle, StringRef skippedToastEnd,
230226
StringSetting behavior, StringSetting color) {
231227
this.keyValue = Objects.requireNonNull(keyValue);
232228
this.title = Objects.requireNonNull(title);
233-
this.description = Objects.requireNonNull(description);
234229
this.skipButtonTextBeginning = Objects.requireNonNull(skipButtonTextBeginning);
235230
this.skipButtonTextMiddle = Objects.requireNonNull(skipButtonTextMiddle);
236231
this.skipButtonTextEnd = Objects.requireNonNull(skipButtonTextEnd);

0 commit comments

Comments
 (0)