fix(YouTube - SponsorBlock): Handle if the user enters an invalid number into any SB settings

This commit is contained in:
LisoUseInAIKyrios 2024-08-20 00:16:42 -04:00
parent 9e11ba11d9
commit 01f084d87a

View File

@ -257,13 +257,19 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment {
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);
@ -309,8 +315,17 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment {
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);
@ -323,6 +338,7 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment {
Utils.showToastLong(str("revanced_sb_general_uuid_invalid"));
return false;
}
Settings.SB_PRIVATE_USER_ID.save(newUUID);
updateUI();
fetchAndDisplayStats();