mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-11-07 20:57:02 +01:00
fix(youtube/sponsorblock): fix saving and loading settings (#304)
This commit is contained in:
parent
5c5a42da40
commit
49aedae3fc
@ -144,8 +144,7 @@ public enum SettingsEnum {
|
|||||||
SB_IS_VIP("sb-is-vip", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
SB_IS_VIP("sb-is-vip", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
||||||
SB_LAST_VIP_CHECK("sb-last-vip-check", 0L, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.LONG),
|
SB_LAST_VIP_CHECK("sb-last-vip-check", 0L, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.LONG),
|
||||||
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
|
||||||
SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING),
|
SB_API_URL("sb-api-host-url", "https://sponsor.ajay.app", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING),
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// old deprecated settings, kept around to migrate user settings on existing installations
|
// old deprecated settings, kept around to migrate user settings on existing installations
|
||||||
@ -365,26 +364,26 @@ public enum SettingsEnum {
|
|||||||
value = newValue;
|
value = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt() {
|
|
||||||
return (int) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString() {
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBoolean() {
|
public boolean getBoolean() {
|
||||||
return (Boolean) value;
|
return (Boolean) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getLong() {
|
public int getInt() {
|
||||||
|
return (Integer) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLong() {
|
||||||
return (Long) value;
|
return (Long) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Float getFloat() {
|
public float getFloat() {
|
||||||
return (Float) value;
|
return (Float) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getString() {
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getDefaultValue() {
|
public Object getDefaultValue() {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
|||||||
setPreferenceScreen(preferenceScreen);
|
setPreferenceScreen(preferenceScreen);
|
||||||
|
|
||||||
enabledPreference = new SwitchPreference(context);
|
enabledPreference = new SwitchPreference(context);
|
||||||
enabledPreference.setKey(SettingsEnum.RYD_ENABLED.getPath());
|
|
||||||
enabledPreference.setDefaultValue(SettingsEnum.RYD_ENABLED.getDefaultValue());
|
|
||||||
enabledPreference.setChecked(SettingsEnum.RYD_ENABLED.getBoolean());
|
enabledPreference.setChecked(SettingsEnum.RYD_ENABLED.getBoolean());
|
||||||
enabledPreference.setTitle(str("revanced_ryd_enable_title"));
|
enabledPreference.setTitle(str("revanced_ryd_enable_title"));
|
||||||
enabledPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
enabledPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||||
@ -77,8 +75,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
|||||||
preferenceScreen.addPreference(enabledPreference);
|
preferenceScreen.addPreference(enabledPreference);
|
||||||
|
|
||||||
percentagePreference = new SwitchPreference(context);
|
percentagePreference = new SwitchPreference(context);
|
||||||
percentagePreference.setKey(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getPath());
|
|
||||||
percentagePreference.setDefaultValue(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getDefaultValue());
|
|
||||||
percentagePreference.setChecked(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getBoolean());
|
percentagePreference.setChecked(SettingsEnum.RYD_SHOW_DISLIKE_PERCENTAGE.getBoolean());
|
||||||
percentagePreference.setTitle(str("revanced_ryd_dislike_percentage_title"));
|
percentagePreference.setTitle(str("revanced_ryd_dislike_percentage_title"));
|
||||||
percentagePreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
percentagePreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||||
@ -90,8 +86,6 @@ public class ReturnYouTubeDislikeSettingsFragment extends PreferenceFragment {
|
|||||||
preferenceScreen.addPreference(percentagePreference);
|
preferenceScreen.addPreference(percentagePreference);
|
||||||
|
|
||||||
compactLayoutPreference = new SwitchPreference(context);
|
compactLayoutPreference = new SwitchPreference(context);
|
||||||
compactLayoutPreference.setKey(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getPath());
|
|
||||||
compactLayoutPreference.setDefaultValue(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getDefaultValue());
|
|
||||||
compactLayoutPreference.setChecked(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean());
|
compactLayoutPreference.setChecked(SettingsEnum.RYD_USE_COMPACT_LAYOUT.getBoolean());
|
||||||
compactLayoutPreference.setTitle(str("revanced_ryd_compact_layout_title"));
|
compactLayoutPreference.setTitle(str("revanced_ryd_compact_layout_title"));
|
||||||
compactLayoutPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
compactLayoutPreference.setOnPreferenceChangeListener((pref, newValue) -> {
|
||||||
|
@ -171,6 +171,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
screen.addPreference(colorPreference);
|
screen.addPreference(colorPreference);
|
||||||
colorPreference.setTitle(str("color_change"));
|
colorPreference.setTitle(str("color_change"));
|
||||||
colorPreference.setSummary(str("color_change_sum"));
|
colorPreference.setSummary(str("color_change_sum"));
|
||||||
|
colorPreference.setSelectable(false);
|
||||||
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
preferencesToDisableWhenSBDisabled.add(colorPreference);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,6 +185,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
Preference preference = new Preference(context);
|
Preference preference = new Preference(context);
|
||||||
category.addPreference(preference);
|
category.addPreference(preference);
|
||||||
preference.setTitle(str("stats_loading"));
|
preference.setTitle(str("stats_loading"));
|
||||||
|
preference.setSelectable(false);
|
||||||
|
|
||||||
SBRequester.retrieveUserStats(category, preference);
|
SBRequester.retrieveUserStats(category, preference);
|
||||||
}
|
}
|
||||||
@ -211,6 +213,7 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
Preference preference = new Preference(context);
|
Preference preference = new Preference(context);
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
preference.setTitle(str("about_madeby"));
|
preference.setTitle(str("about_madeby"));
|
||||||
|
preference.setSelectable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -233,11 +236,14 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Preference preference = new SwitchPreference(context);
|
SwitchPreference preference = new SwitchPreference(context);
|
||||||
preference.setTitle(str("general_skiptoast"));
|
preference.setTitle(str("general_skiptoast"));
|
||||||
preference.setSummary(str("general_skiptoast_sum"));
|
preference.setSummary(str("general_skiptoast_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getPath());
|
preference.setChecked(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getBoolean());
|
||||||
preference.setDefaultValue(SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getDefaultValue());
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.saveValue(newValue);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
preference.setOnPreferenceClickListener(preference12 -> {
|
preference.setOnPreferenceClickListener(preference12 -> {
|
||||||
Toast.makeText(preference12.getContext(), str("skipped_sponsor"), Toast.LENGTH_SHORT).show();
|
Toast.makeText(preference12.getContext(), str("skipped_sponsor"), Toast.LENGTH_SHORT).show();
|
||||||
return false;
|
return false;
|
||||||
@ -247,21 +253,28 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Preference preference = new SwitchPreference(context);
|
SwitchPreference preference = new SwitchPreference(context);
|
||||||
preference.setTitle(str("general_skipcount"));
|
preference.setTitle(str("general_skipcount"));
|
||||||
preference.setSummary(str("general_skipcount_sum"));
|
preference.setSummary(str("general_skipcount_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_COUNT_SKIPS.getPath());
|
preference.setChecked(SettingsEnum.SB_COUNT_SKIPS.getBoolean());
|
||||||
preference.setDefaultValue(SettingsEnum.SB_COUNT_SKIPS.getDefaultValue());
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_COUNT_SKIPS.saveValue(newValue);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
preferencesToDisableWhenSBDisabled.add(preference);
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Preference preference = new SwitchPreference(context);
|
SwitchPreference preference = new SwitchPreference(context);
|
||||||
preference.setTitle(str("general_time_without_sb"));
|
preference.setTitle(str("general_time_without_sb"));
|
||||||
preference.setSummary(str("general_time_without_sb_sum"));
|
preference.setSummary(str("general_time_without_sb_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getPath());
|
preference.setChecked(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean());
|
||||||
preference.setDefaultValue(SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getDefaultValue());
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.saveValue(newValue);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
preferencesToDisableWhenSBDisabled.add(preference);
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
}
|
}
|
||||||
@ -271,8 +284,11 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||||
preference.setTitle(str("general_adjusting"));
|
preference.setTitle(str("general_adjusting"));
|
||||||
preference.setSummary(str("general_adjusting_sum"));
|
preference.setSummary(str("general_adjusting_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getPath());
|
preference.setText(String.valueOf(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getInt()));
|
||||||
preference.setDefaultValue(SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.getDefaultValue() + "");
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_ADJUST_NEW_SEGMENT_STEP.saveValue(Integer.valueOf(newValue.toString()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
preferencesToDisableWhenSBDisabled.add(preference);
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
}
|
}
|
||||||
@ -282,18 +298,25 @@ public class SponsorBlockSettingsFragment extends PreferenceFragment implements
|
|||||||
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
preference.getEditText().setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
|
||||||
preference.setTitle(str("general_min_duration"));
|
preference.setTitle(str("general_min_duration"));
|
||||||
preference.setSummary(str("general_min_duration_sum"));
|
preference.setSummary(str("general_min_duration_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_MIN_DURATION.getPath());
|
preference.setText(String.valueOf(SettingsEnum.SB_MIN_DURATION.getFloat()));
|
||||||
preference.setDefaultValue(SettingsEnum.SB_MIN_DURATION.getDefaultValue() + "");
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_MIN_DURATION.saveValue(Float.valueOf(newValue.toString()));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
preferencesToDisableWhenSBDisabled.add(preference);
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Preference preference = new EditTextPreference(context);
|
EditTextPreference preference = new EditTextPreference(context);
|
||||||
preference.setTitle(str("general_uuid"));
|
preference.setTitle(str("general_uuid"));
|
||||||
preference.setSummary(str("general_uuid_sum"));
|
preference.setSummary(str("general_uuid_sum"));
|
||||||
preference.setKey(SettingsEnum.SB_UUID.getPath());
|
preference.setText(SettingsEnum.SB_UUID.getString());
|
||||||
preference.setDefaultValue(SettingsEnum.SB_UUID.getDefaultValue() + "");
|
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
|
||||||
|
SettingsEnum.SB_UUID.saveValue(newValue.toString());
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
screen.addPreference(preference);
|
screen.addPreference(preference);
|
||||||
preferencesToDisableWhenSBDisabled.add(preference);
|
preferencesToDisableWhenSBDisabled.add(preference);
|
||||||
}
|
}
|
||||||
|
@ -193,14 +193,13 @@ public class PlayerController {
|
|||||||
SettingsEnum.SB_SKIPPED_SEGMENTS_TIME.saveValue(newSkippedTime);
|
SettingsEnum.SB_SKIPPED_SEGMENTS_TIME.saveValue(newSkippedTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
if (SettingsEnum.SB_COUNT_SKIPS.getBoolean()
|
||||||
if (SettingsEnum.SB_COUNT_SKIPS.getBoolean() &&
|
&& segment.category != SponsorBlockSettings.SegmentInfo.UNSUBMITTED
|
||||||
segment.category != SponsorBlockSettings.SegmentInfo.UNSUBMITTED &&
|
&& millis - segment.start < 2000) { // Only skips from the start should count as a view
|
||||||
millis - segment.start < 2000) {
|
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||||
// Only skips from the start should count as a view
|
|
||||||
SBRequester.sendViewCountRequest(segment);
|
SBRequester.sendViewCountRequest(segment);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHighPrecisionVideoTime(final long millis) {
|
public static void setHighPrecisionVideoTime(final long millis) {
|
||||||
|
@ -83,7 +83,7 @@ public class SponsorBlockSettings {
|
|||||||
sponsorBlockUrlCategories = "[%22" + TextUtils.join("%22,%22", enabledCategories) + "%22]";
|
sponsorBlockUrlCategories = "[%22" + TextUtils.join("%22,%22", enabledCategories) + "%22]";
|
||||||
|
|
||||||
String uuid = SettingsEnum.SB_UUID.getString();
|
String uuid = SettingsEnum.SB_UUID.getString();
|
||||||
if (uuid == null) {
|
if (uuid == null || uuid.length() == 0) {
|
||||||
uuid = (UUID.randomUUID().toString() +
|
uuid = (UUID.randomUUID().toString() +
|
||||||
UUID.randomUUID().toString() +
|
UUID.randomUUID().toString() +
|
||||||
UUID.randomUUID().toString())
|
UUID.randomUUID().toString())
|
||||||
|
@ -46,6 +46,7 @@ import java.util.TimeZone;
|
|||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
import app.revanced.integrations.sponsorblock.player.PlayerType;
|
import app.revanced.integrations.sponsorblock.player.PlayerType;
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
import app.revanced.integrations.utils.SharedPrefHelper;
|
import app.revanced.integrations.utils.SharedPrefHelper;
|
||||||
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
||||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||||
@ -153,7 +154,7 @@ public abstract class SponsorBlockUtils {
|
|||||||
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, str("submit_started"), Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
appContext = new WeakReference<>(context);
|
appContext = new WeakReference<>(context);
|
||||||
new Thread(submitRunnable).start(); // fixme: use ReVancedUtils#runOnBackgroundThread
|
ReVancedUtils.runOnBackgroundThread(submitRunnable);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
public static String messageToToast = "";
|
public static String messageToToast = "";
|
||||||
@ -473,6 +474,7 @@ public abstract class SponsorBlockUtils {
|
|||||||
category.addPreference(preference);
|
category.addPreference(preference);
|
||||||
String formatted = FORMATTER.format(stats.getSegmentCount());
|
String formatted = FORMATTER.format(stats.getSegmentCount());
|
||||||
preference.setTitle(fromHtml(str("stats_submissions", formatted)));
|
preference.setTitle(fromHtml(str("stats_submissions", formatted)));
|
||||||
|
preference.setSelectable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -506,6 +508,7 @@ public abstract class SponsorBlockUtils {
|
|||||||
|
|
||||||
preference.setTitle(fromHtml(str("stats_self_saved", formatted)));
|
preference.setTitle(fromHtml(str("stats_self_saved", formatted)));
|
||||||
preference.setSummary(fromHtml(str("stats_self_saved_sum", formattedSaved)));
|
preference.setSummary(fromHtml(str("stats_self_saved_sum", formattedSaved)));
|
||||||
|
preference.setSelectable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,20 +547,13 @@ public abstract class SponsorBlockUtils {
|
|||||||
editor.putString(category.key, behaviour.key);
|
editor.putString(category.key, behaviour.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsEnum.SB_UUID.saveValue(settingsJson.getString("userID"));
|
||||||
|
SettingsEnum.SB_IS_VIP.saveValue(settingsJson.getBoolean("isVip"));
|
||||||
|
SettingsEnum.SB_API_URL.saveValue(settingsJson.getString("serverAddress"));
|
||||||
SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.saveValue(!settingsJson.getBoolean("dontShowNotice"));
|
SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.saveValue(!settingsJson.getBoolean("dontShowNotice"));
|
||||||
SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.saveValue(settingsJson.getBoolean("showTimeWithSkips"));
|
SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.saveValue(settingsJson.getBoolean("showTimeWithSkips"));
|
||||||
SettingsEnum.SB_COUNT_SKIPS.saveValue(settingsJson.getBoolean("trackViewCount"));
|
|
||||||
SettingsEnum.SB_IS_VIP.saveValue(settingsJson.getBoolean("isVip"));
|
|
||||||
SettingsEnum.SB_MIN_DURATION.saveValue(Float.valueOf(settingsJson.getString("minDuration")));
|
SettingsEnum.SB_MIN_DURATION.saveValue(Float.valueOf(settingsJson.getString("minDuration")));
|
||||||
SettingsEnum.SB_UUID.saveValue(settingsJson.getString("userID"));
|
SettingsEnum.SB_COUNT_SKIPS.saveValue(settingsJson.getBoolean("trackViewCount"));
|
||||||
SettingsEnum.SB_LAST_VIP_CHECK.saveValue(settingsJson.getLong("lastIsVipUpdate"));
|
|
||||||
|
|
||||||
|
|
||||||
String serverAddress = settingsJson.getString("serverAddress");
|
|
||||||
if (serverAddress.equalsIgnoreCase("https://sponsor.ajay.app")) {
|
|
||||||
serverAddress = (String) SettingsEnum.SB_API_URL.getDefaultValue();
|
|
||||||
}
|
|
||||||
SettingsEnum.SB_API_URL.saveValue(serverAddress);
|
|
||||||
|
|
||||||
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -588,16 +584,15 @@ public abstract class SponsorBlockUtils {
|
|||||||
categorySelectionsArray.put(behaviorObject);
|
categorySelectionsArray.put(behaviorObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
json.put("userID", SettingsEnum.SB_UUID.getString());
|
||||||
|
json.put("isVip", SettingsEnum.SB_IS_VIP.getBoolean());
|
||||||
|
json.put("serverAddress", SettingsEnum.SB_API_URL.getString());
|
||||||
json.put("dontShowNotice", !SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getBoolean());
|
json.put("dontShowNotice", !SettingsEnum.SB_SHOW_TOAST_WHEN_SKIP.getBoolean());
|
||||||
json.put("barTypes", barTypesObject);
|
|
||||||
json.put("showTimeWithSkips", SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean());
|
json.put("showTimeWithSkips", SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean());
|
||||||
json.put("minDuration", SettingsEnum.SB_MIN_DURATION.getFloat());
|
json.put("minDuration", SettingsEnum.SB_MIN_DURATION.getFloat());
|
||||||
json.put("trackViewCount", SettingsEnum.SB_COUNT_SKIPS.getBoolean());
|
json.put("trackViewCount", SettingsEnum.SB_COUNT_SKIPS.getBoolean());
|
||||||
json.put("categorySelections", categorySelectionsArray);
|
json.put("categorySelections", categorySelectionsArray);
|
||||||
json.put("userID", SettingsEnum.SB_UUID.getString());
|
json.put("barTypes", barTypesObject);
|
||||||
json.put("isVip", SettingsEnum.SB_IS_VIP.getBoolean());
|
|
||||||
json.put("lastIsVipUpdate", SettingsEnum.SB_LAST_VIP_CHECK.getLong());
|
|
||||||
json.put("serverAddress", SettingsEnum.SB_API_URL.getString());
|
|
||||||
|
|
||||||
return json.toString();
|
return json.toString();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -31,6 +31,7 @@ import app.revanced.integrations.sponsorblock.SponsorBlockUtils;
|
|||||||
import app.revanced.integrations.sponsorblock.SponsorBlockUtils.VoteOption;
|
import app.revanced.integrations.sponsorblock.SponsorBlockUtils.VoteOption;
|
||||||
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
import app.revanced.integrations.sponsorblock.objects.SponsorSegment;
|
||||||
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
import app.revanced.integrations.sponsorblock.objects.UserStats;
|
||||||
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
|
||||||
public class SBRequester {
|
public class SBRequester {
|
||||||
@ -130,14 +131,12 @@ public class SBRequester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, String... args) {
|
public static void voteForSegment(SponsorSegment segment, VoteOption voteOption, Context context, String... args) {
|
||||||
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||||
try {
|
try {
|
||||||
String segmentUuid = segment.UUID;
|
String segmentUuid = segment.UUID;
|
||||||
String uuid = SettingsEnum.SB_UUID.getString();
|
String uuid = SettingsEnum.SB_UUID.getString();
|
||||||
String vote = Integer.toString(voteOption == VoteOption.UPVOTE ? 1 : 0);
|
String vote = Integer.toString(voteOption == VoteOption.UPVOTE ? 1 : 0);
|
||||||
|
|
||||||
runOnMainThread(() -> Toast.makeText(context, str("vote_started"), Toast.LENGTH_SHORT).show());
|
|
||||||
|
|
||||||
HttpURLConnection connection = voteOption == VoteOption.CATEGORY_CHANGE
|
HttpURLConnection connection = voteOption == VoteOption.CATEGORY_CHANGE
|
||||||
? getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_CATEGORY, segmentUuid, uuid, args[0])
|
? getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_CATEGORY, segmentUuid, uuid, args[0])
|
||||||
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, segmentUuid, uuid, vote);
|
: getConnectionFromRoute(SBRoutes.VOTE_ON_SEGMENT_QUALITY, segmentUuid, uuid, vote);
|
||||||
@ -159,7 +158,7 @@ public class SBRequester {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> "failed to vote for segment", ex);
|
LogHelper.printException(() -> "failed to vote for segment", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void retrieveUserStats(PreferenceCategory category, Preference loadingPreference) {
|
public static void retrieveUserStats(PreferenceCategory category, Preference loadingPreference) {
|
||||||
@ -168,20 +167,22 @@ public class SBRequester {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||||
try {
|
try {
|
||||||
JSONObject json = getJSONObject(SBRoutes.GET_USER_STATS, SettingsEnum.SB_UUID.getString());
|
JSONObject json = getJSONObject(SBRoutes.GET_USER_STATS, SettingsEnum.SB_UUID.getString());
|
||||||
UserStats stats = new UserStats(json.getString("userName"), json.getDouble("minutesSaved"), json.getInt("segmentCount"),
|
UserStats stats = new UserStats(json.getString("userName"), json.getDouble("minutesSaved"), json.getInt("segmentCount"),
|
||||||
json.getInt("viewCount"));
|
json.getInt("viewCount"));
|
||||||
|
runOnMainThread(() -> { // get back on main thread to modify UI elements
|
||||||
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
SponsorBlockUtils.addUserStats(category, loadingPreference, stats);
|
||||||
|
});
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> "failed to retrieve user stats", ex);
|
LogHelper.printException(() -> "failed to retrieve user stats", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
public static void setUsername(String username, EditTextPreference preference, Runnable toastRunnable) {
|
||||||
new Thread(() -> { // fixme: use ReVancedUtils#runOnBackgroundThread
|
ReVancedUtils.runOnBackgroundThread(() -> {
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SettingsEnum.SB_UUID.getString(), username);
|
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.CHANGE_USERNAME, SettingsEnum.SB_UUID.getString(), username);
|
||||||
int responseCode = connection.getResponseCode();
|
int responseCode = connection.getResponseCode();
|
||||||
@ -200,7 +201,7 @@ public class SBRequester {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
LogHelper.printException(() -> "failed to set username", ex);
|
LogHelper.printException(() -> "failed to set username", ex);
|
||||||
}
|
}
|
||||||
}).start();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runVipCheck() {
|
public static void runVipCheck() {
|
||||||
|
@ -5,15 +5,15 @@ import static app.revanced.integrations.requests.Route.Method.POST;
|
|||||||
|
|
||||||
import app.revanced.integrations.requests.Route;
|
import app.revanced.integrations.requests.Route;
|
||||||
|
|
||||||
public class SBRoutes {
|
class SBRoutes {
|
||||||
public static final Route IS_USER_VIP = new Route(GET, "isUserVIP?userID={user_id}");
|
static final Route IS_USER_VIP = new Route(GET, "/api/isUserVIP?userID={user_id}");
|
||||||
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
static final Route GET_SEGMENTS = new Route(GET, "/api/skipSegments?videoID={video_id}&categories={categories}");
|
||||||
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
static final Route VIEWED_SEGMENT = new Route(POST, "/api/viewedVideoSponsorTime?UUID={segment_id}");
|
||||||
public static final Route GET_USER_STATS = new Route(GET, "userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
static final Route GET_USER_STATS = new Route(GET, "/api/userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
||||||
public static final Route CHANGE_USERNAME = new Route(POST, "setUsername?userID={user_id}&username={username}");
|
static final Route CHANGE_USERNAME = new Route(POST, "/api/setUsername?userID={user_id}&username={username}");
|
||||||
public static final Route SUBMIT_SEGMENTS = new Route(POST, "skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}&videoDuration={duration}");
|
static final Route SUBMIT_SEGMENTS = new Route(POST, "/api/skipSegments?videoID={video_id}&userID={user_id}&startTime={start_time}&endTime={end_time}&category={category}&videoDuration={duration}");
|
||||||
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "/api/voteOnSponsorTime?UUID={segment_id}&userID={user_id}&type={type}");
|
||||||
public static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
static final Route VOTE_ON_SEGMENT_CATEGORY = new Route(POST, "/api/voteOnSponsorTime?UUID={segment_id}&userID={user_id}&category={category}");
|
||||||
|
|
||||||
private SBRoutes() {
|
private SBRoutes() {
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class ReVancedUtils {
|
|||||||
* All tasks run at max thread priority.
|
* All tasks run at max thread priority.
|
||||||
*/
|
*/
|
||||||
private static final ThreadPoolExecutor backgroundThreadPool = new ThreadPoolExecutor(
|
private static final ThreadPoolExecutor backgroundThreadPool = new ThreadPoolExecutor(
|
||||||
1, // minimum 1 thread always ready to be used
|
2, // minimum 2 threads always ready to be used
|
||||||
10, // For any threads over the minimum, keep them alive 10 seconds after they go idle
|
10, // For any threads over the minimum, keep them alive 10 seconds after they go idle
|
||||||
SHARED_THREAD_POOL_MAXIMUM_BACKGROUND_THREADS,
|
SHARED_THREAD_POOL_MAXIMUM_BACKGROUND_THREADS,
|
||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
|
Loading…
Reference in New Issue
Block a user