Skip to content

Commit

Permalink
fix(YouTube - SponsorBlock): Handle if the user enters an invalid num…
Browse files Browse the repository at this point in the history
…ber into any SB settings
  • Loading branch information
LisoUseInAIKyrios committed Aug 20, 2024
1 parent 9e11ba1 commit 01f084d
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,19 @@ private void addCreateSegmentCategory(Context context, PreferenceScreen screen)
newSegmentStep.setSummary(str("revanced_sb_general_adjusting_sum"));
newSegmentStep.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
newSegmentStep.setOnPreferenceChangeListener((preference1, newValue) -> {
final int newAdjustmentValue = Integer.parseInt(newValue.toString());
if (newAdjustmentValue == 0) {
Utils.showToastLong(str("revanced_sb_general_adjusting_invalid"));
return false;
try {
final int newAdjustmentValue = Integer.parseInt(newValue.toString());
if (newAdjustmentValue != 0) {
Settings.SB_CREATE_NEW_SEGMENT_STEP.save(newAdjustmentValue);
return true;
}
} catch (NumberFormatException ex) {
Logger.printInfo(() -> "Invalid new segment step", ex);
}
Settings.SB_CREATE_NEW_SEGMENT_STEP.save(newAdjustmentValue);
return true;

Utils.showToastLong(str("revanced_sb_general_adjusting_invalid"));
updateUI();
return false;
});
category.addPreference(newSegmentStep);

Expand Down Expand Up @@ -309,8 +315,17 @@ private void addGeneralCategory(final Context context, PreferenceScreen screen)
minSegmentDuration.setSummary(str("revanced_sb_general_min_duration_sum"));
minSegmentDuration.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
minSegmentDuration.setOnPreferenceChangeListener((preference1, newValue) -> {
Settings.SB_SEGMENT_MIN_DURATION.save(Float.valueOf(newValue.toString()));
return true;
try {
Float minTimeDuration = Float.valueOf(newValue.toString());
Settings.SB_SEGMENT_MIN_DURATION.save(minTimeDuration);
return true;
} catch (NumberFormatException ex) {
Logger.printInfo(() -> "Invalid minimum segment duration", ex);
}

Utils.showToastLong(str("revanced_sb_general_min_duration_invalid"));
updateUI();
return false;
});
category.addPreference(minSegmentDuration);

Expand All @@ -323,6 +338,7 @@ private void addGeneralCategory(final Context context, PreferenceScreen screen)
Utils.showToastLong(str("revanced_sb_general_uuid_invalid"));
return false;
}

Settings.SB_PRIVATE_USER_ID.save(newUUID);
updateUI();
fetchAndDisplayStats();
Expand Down

0 comments on commit 01f084d

Please # to comment.