import/export api url

This commit is contained in:
caneleex 2022-02-07 16:29:42 +01:00
parent e5c6cff7dc
commit 9a45757824
3 changed files with 34 additions and 16 deletions

View File

@ -342,21 +342,6 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
preferencesToDisableWhenSBDisabled.add(preference);
}
{
EditTextPreference preference = new EditTextPreference(context);
Context applicationContext = context.getApplicationContext();
preference.setTitle(str("settings_ie"));
preference.setSummary(str("settings_ie_sum"));
preference.setText(SponsorBlockUtils.exportSettings(applicationContext));
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
SponsorBlockUtils.importSettings((String) newValue, applicationContext);
return false;
});
screen.addPreference(preference);
preferencesToDisableWhenSBDisabled.add(preference);
}
{
Preference preference = new Preference(context);
String title = str("general_api_url");
@ -381,6 +366,21 @@ public class SponsorBlockPreferenceFragment extends PreferenceFragment implement
screen.addPreference(preference);
preferencesToDisableWhenSBDisabled.add(preference);
}
{
EditTextPreference preference = new EditTextPreference(context);
Context applicationContext = context.getApplicationContext();
preference.setTitle(str("settings_ie"));
preference.setSummary(str("settings_ie_sum"));
preference.setText(SponsorBlockUtils.exportSettings(applicationContext));
preference.setOnPreferenceChangeListener((preference1, newValue) -> {
SponsorBlockUtils.importSettings((String) newValue, applicationContext);
return false;
});
screen.addPreference(preference);
preferencesToDisableWhenSBDisabled.add(preference);
}
}
private static class APIURLChangeListener implements DialogInterface.OnClickListener {

View File

@ -38,7 +38,8 @@ public class SponsorBlockSettings {
public static final String PREFERENCES_KEY_API_URL = "sb-api-url";
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY;
public static final String DEFAULT_API_URL = "https://sponsor.ajay.app/api/";
public static final String DEFAULT_SERVER_URL = "https://sponsor.ajay.app";
public static final String DEFAULT_API_URL = DEFAULT_SERVER_URL + "/api/";
public static boolean isSponsorBlockEnabled = false;
public static boolean seenGuidelinesPopup = false;

View File

@ -10,6 +10,9 @@ import static pl.jakubweg.PlayerController.getLastKnownVideoTime;
import static pl.jakubweg.PlayerController.sponsorSegmentsOfCurrentVideo;
import static pl.jakubweg.SponsorBlockPreferenceFragment.FORMATTER;
import static pl.jakubweg.SponsorBlockPreferenceFragment.SAVED_TEMPLATE;
import static pl.jakubweg.SponsorBlockSettings.DEFAULT_API_URL;
import static pl.jakubweg.SponsorBlockSettings.DEFAULT_SERVER_URL;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_API_URL;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_COUNT_SKIPS;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_IS_VIP;
@ -19,6 +22,7 @@ import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_UUID;
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_NAME;
import static pl.jakubweg.SponsorBlockSettings.apiUrl;
import static pl.jakubweg.SponsorBlockSettings.countSkips;
import static pl.jakubweg.SponsorBlockSettings.getPreferences;
import static pl.jakubweg.SponsorBlockSettings.isSponsorBlockEnabled;
@ -571,6 +575,13 @@ public abstract class SponsorBlockUtils {
editor.putString(PREFERENCES_KEY_MIN_DURATION, settingsJson.getString("minDuration"));
editor.putString(PREFERENCES_KEY_UUID, settingsJson.getString("userID"));
editor.putString(PREFERENCES_KEY_LAST_VIP_CHECK, settingsJson.getString("lastIsVipUpdate"));
String serverAddress = settingsJson.getString("serverAddress");
if (serverAddress.equalsIgnoreCase(DEFAULT_SERVER_URL)) {
serverAddress = DEFAULT_API_URL;
}
editor.putString(PREFERENCES_KEY_API_URL, serverAddress);
editor.apply();
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
@ -613,6 +624,12 @@ public abstract class SponsorBlockUtils {
json.put("isVip", vip);
json.put("lastIsVipUpdate", lastVipCheck);
String apiAddress = apiUrl;
if (apiAddress.equalsIgnoreCase(DEFAULT_API_URL)) {
apiAddress = DEFAULT_SERVER_URL;
}
json.put("serverAddress", apiAddress);
return json.toString();
}
catch (Exception ex) {