mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-05 17:45:49 +01:00
mark locked segments as orange if vip
This commit is contained in:
parent
e3ec5430c9
commit
e5c6cff7dc
@ -33,6 +33,8 @@ public class SponsorBlockSettings {
|
||||
public static final String PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS = "sb-length-without-segments";
|
||||
public static final String PREFERENCES_KEY_CATEGORY_COLOR_SUFFIX = "_color";
|
||||
public static final String PREFERENCES_KEY_BROWSER_BUTTON = "sb-browser-button";
|
||||
public static final String PREFERENCES_KEY_IS_VIP = "sb-is-vip";
|
||||
public static final String PREFERENCES_KEY_LAST_VIP_CHECK = "sb-last-vip-check";
|
||||
public static final String PREFERENCES_KEY_API_URL = "sb-api-url";
|
||||
|
||||
public static final SegmentBehaviour DefaultBehaviour = SegmentBehaviour.SKIP_AUTOMATICALLY;
|
||||
@ -45,6 +47,8 @@ public class SponsorBlockSettings {
|
||||
public static boolean showToastWhenSkippedAutomatically = true;
|
||||
public static boolean countSkips = true;
|
||||
public static boolean showTimeWithoutSegments = true;
|
||||
public static boolean vip = false;
|
||||
public static long lastVipCheck = 0;
|
||||
public static int adjustNewSegmentMillis = 150;
|
||||
public static float minDuration = 0f;
|
||||
public static String uuid = "<invalid>";
|
||||
@ -146,6 +150,11 @@ public class SponsorBlockSettings {
|
||||
|
||||
countSkips = preferences.getBoolean(PREFERENCES_KEY_COUNT_SKIPS, countSkips);
|
||||
showTimeWithoutSegments = preferences.getBoolean(PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS, showTimeWithoutSegments);
|
||||
vip = preferences.getBoolean(PREFERENCES_KEY_IS_VIP, false);
|
||||
|
||||
String vipCheckTmp = preferences.getString(PREFERENCES_KEY_LAST_VIP_CHECK, null);
|
||||
if (vipCheckTmp != null)
|
||||
lastVipCheck = Long.parseLong(vipCheckTmp);
|
||||
|
||||
apiUrl = preferences.getString(PREFERENCES_KEY_API_URL, DEFAULT_API_URL);
|
||||
|
||||
|
@ -12,6 +12,8 @@ import static pl.jakubweg.SponsorBlockPreferenceFragment.FORMATTER;
|
||||
import static pl.jakubweg.SponsorBlockPreferenceFragment.SAVED_TEMPLATE;
|
||||
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;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_LAST_VIP_CHECK;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_MIN_DURATION;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS;
|
||||
import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP;
|
||||
@ -20,12 +22,14 @@ import static pl.jakubweg.SponsorBlockSettings.PREFERENCES_NAME;
|
||||
import static pl.jakubweg.SponsorBlockSettings.countSkips;
|
||||
import static pl.jakubweg.SponsorBlockSettings.getPreferences;
|
||||
import static pl.jakubweg.SponsorBlockSettings.isSponsorBlockEnabled;
|
||||
import static pl.jakubweg.SponsorBlockSettings.lastVipCheck;
|
||||
import static pl.jakubweg.SponsorBlockSettings.minDuration;
|
||||
import static pl.jakubweg.SponsorBlockSettings.showTimeWithoutSegments;
|
||||
import static pl.jakubweg.SponsorBlockSettings.showToastWhenSkippedAutomatically;
|
||||
import static pl.jakubweg.SponsorBlockSettings.skippedSegments;
|
||||
import static pl.jakubweg.SponsorBlockSettings.skippedTime;
|
||||
import static pl.jakubweg.SponsorBlockSettings.uuid;
|
||||
import static pl.jakubweg.SponsorBlockSettings.vip;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
import static pl.jakubweg.requests.SBRequester.voteForSegment;
|
||||
|
||||
@ -74,6 +78,7 @@ public abstract class SponsorBlockUtils {
|
||||
public static boolean videoHasSegments = false;
|
||||
public static String timeWithoutSegments = "";
|
||||
private static final int sponsorBtnId = 1234;
|
||||
private static final String LOCKED_COLOR = "#FFC83D";
|
||||
public static final View.OnClickListener sponsorBlockBtnListener = v -> {
|
||||
if (debug) {
|
||||
Log.d(TAG, "Shield button clicked");
|
||||
@ -214,10 +219,17 @@ public abstract class SponsorBlockUtils {
|
||||
final SponsorSegment segment = sponsorSegmentsOfCurrentVideo[which];
|
||||
|
||||
final VoteOption[] voteOptions = VoteOption.values();
|
||||
String[] items = new String[voteOptions.length];
|
||||
CharSequence[] items = new CharSequence[voteOptions.length];
|
||||
|
||||
for (int i = 0; i < voteOptions.length; i++) {
|
||||
items[i] = voteOptions[i].title;
|
||||
VoteOption voteOption = voteOptions[i];
|
||||
String title = voteOption.title;
|
||||
if (vip && segment.isLocked && voteOption.shouldHighlight) {
|
||||
items[i] = Html.fromHtml(String.format("<font color=\"%s\">%s</font>", LOCKED_COLOR, title));
|
||||
}
|
||||
else {
|
||||
items[i] = title;
|
||||
}
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
@ -383,7 +395,7 @@ public abstract class SponsorBlockUtils {
|
||||
final SponsorSegment[] segments = original == null ? new SponsorSegment[1] : Arrays.copyOf(original, original.length + 1);
|
||||
|
||||
segments[segments.length - 1] = new SponsorSegment(newSponsorSegmentStartMillis, newSponsorSegmentEndMillis,
|
||||
SponsorBlockSettings.SegmentInfo.UNSUBMITTED, null);
|
||||
SponsorBlockSettings.SegmentInfo.UNSUBMITTED, null, false);
|
||||
|
||||
Arrays.sort(segments);
|
||||
sponsorSegmentsOfCurrentVideo = segments;
|
||||
@ -555,8 +567,10 @@ public abstract class SponsorBlockUtils {
|
||||
editor.putBoolean(PREFERENCES_KEY_SHOW_TOAST_WHEN_SKIP, !settingsJson.getBoolean("dontShowNotice"));
|
||||
editor.putBoolean(PREFERENCES_KEY_SHOW_TIME_WITHOUT_SEGMENTS, settingsJson.getBoolean("showTimeWithSkips"));
|
||||
editor.putBoolean(PREFERENCES_KEY_COUNT_SKIPS, settingsJson.getBoolean("trackViewCount"));
|
||||
editor.putBoolean(PREFERENCES_KEY_IS_VIP, settingsJson.getBoolean("isVip"));
|
||||
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"));
|
||||
editor.apply();
|
||||
|
||||
Toast.makeText(context, str("settings_import_successful"), Toast.LENGTH_SHORT).show();
|
||||
@ -596,6 +610,8 @@ public abstract class SponsorBlockUtils {
|
||||
json.put("trackViewCount", countSkips);
|
||||
json.put("categorySelections", categorySelectionsArray);
|
||||
json.put("userID", uuid);
|
||||
json.put("isVip", vip);
|
||||
json.put("lastIsVipUpdate", lastVipCheck);
|
||||
|
||||
return json.toString();
|
||||
}
|
||||
@ -615,14 +631,17 @@ public abstract class SponsorBlockUtils {
|
||||
}
|
||||
|
||||
public enum VoteOption {
|
||||
UPVOTE(str("vote_upvote")),
|
||||
DOWNVOTE(str("vote_downvote")),
|
||||
CATEGORY_CHANGE(str("vote_category"));
|
||||
UPVOTE(str("vote_upvote"), false),
|
||||
DOWNVOTE(str("vote_downvote"), true),
|
||||
CATEGORY_CHANGE(str("vote_category"), true);
|
||||
|
||||
public final String title;
|
||||
public final boolean shouldHighlight;
|
||||
|
||||
VoteOption(String title) {
|
||||
|
||||
VoteOption(String title, boolean shouldHighlight) {
|
||||
this.title = title;
|
||||
this.shouldHighlight = shouldHighlight;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,14 @@ public class SponsorSegment implements Comparable<SponsorSegment> {
|
||||
public final long end;
|
||||
public final SponsorBlockSettings.SegmentInfo category;
|
||||
public final String UUID;
|
||||
public final boolean isLocked;
|
||||
|
||||
public SponsorSegment(long start, long end, SponsorBlockSettings.SegmentInfo category, String UUID) {
|
||||
public SponsorSegment(long start, long end, SponsorBlockSettings.SegmentInfo category, String UUID, boolean isLocked) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.category = category;
|
||||
this.UUID = UUID;
|
||||
this.isLocked = isLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -21,6 +23,7 @@ public class SponsorSegment implements Comparable<SponsorSegment> {
|
||||
"start=" + start +
|
||||
", end=" + end +
|
||||
", category='" + category + '\'' +
|
||||
", locked=" + isLocked +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,14 @@ import static pl.jakubweg.SponsorBlockUtils.videoHasSegments;
|
||||
import static pl.jakubweg.StringRef.str;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -20,6 +23,7 @@ import java.net.HttpURLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import fi.vanced.utils.requests.Requester;
|
||||
import fi.vanced.utils.requests.Route;
|
||||
@ -40,6 +44,7 @@ public class SBRequester {
|
||||
try {
|
||||
HttpURLConnection connection = getConnectionFromRoute(SBRoutes.GET_SEGMENTS, videoId, SponsorBlockSettings.sponsorBlockUrlCategories);
|
||||
int responseCode = connection.getResponseCode();
|
||||
runVipCheck();
|
||||
|
||||
if (responseCode == 200) {
|
||||
JSONArray responseArray = Requester.getJSONArray(connection);
|
||||
@ -56,10 +61,11 @@ public class SBRequester {
|
||||
|
||||
String category = obj.getString("category");
|
||||
String uuid = obj.getString("UUID");
|
||||
boolean locked = obj.getInt("locked") == 1;
|
||||
|
||||
SponsorBlockSettings.SegmentInfo segmentCategory = SponsorBlockSettings.SegmentInfo.byCategoryKey(category);
|
||||
if (segmentCategory != null && segmentCategory.behaviour.showOnTimeBar) {
|
||||
SponsorSegment sponsorSegment = new SponsorSegment(start, end, segmentCategory, uuid);
|
||||
SponsorSegment sponsorSegment = new SponsorSegment(start, end, segmentCategory, uuid, locked);
|
||||
segments.add(sponsorSegment);
|
||||
}
|
||||
}
|
||||
@ -197,6 +203,27 @@ public class SBRequester {
|
||||
}).start();
|
||||
}
|
||||
|
||||
public static void runVipCheck() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now < (SponsorBlockSettings.lastVipCheck + TimeUnit.DAYS.toMillis(3))) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONObject json = getJSONObject(SBRoutes.IS_USER_VIP, SponsorBlockSettings.uuid);
|
||||
boolean vip = json.getBoolean("vip");
|
||||
SponsorBlockSettings.vip = vip;
|
||||
SponsorBlockSettings.lastVipCheck = now;
|
||||
|
||||
SharedPreferences.Editor edit = SponsorBlockSettings.getPreferences(YouTubeTikTokRoot_Application.getAppContext()).edit();
|
||||
edit.putString(SponsorBlockSettings.PREFERENCES_KEY_LAST_VIP_CHECK, String.valueOf(now));
|
||||
edit.putBoolean(SponsorBlockSettings.PREFERENCES_KEY_IS_VIP, vip);
|
||||
edit.apply();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
private static HttpURLConnection getConnectionFromRoute(Route route, String... params) throws IOException {
|
||||
|
@ -6,13 +6,14 @@ import static fi.vanced.utils.requests.Route.Method.POST;
|
||||
import fi.vanced.utils.requests.Route;
|
||||
|
||||
public class SBRoutes {
|
||||
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
||||
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
||||
public static final Route GET_USER_STATS = new Route(GET, "userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
||||
public static final Route CHANGE_USERNAME = new Route(POST, "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}");
|
||||
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "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}");
|
||||
public static final Route IS_USER_VIP = new Route(GET, "isUserVIP?userID={user_id}");
|
||||
public static final Route GET_SEGMENTS = new Route(GET, "skipSegments?videoID={video_id}&categories={categories}");
|
||||
public static final Route VIEWED_SEGMENT = new Route(POST, "viewedVideoSponsorTime?UUID={segment_id}");
|
||||
public static final Route GET_USER_STATS = new Route(GET, "userInfo?userID={user_id}&values=[\"userName\", \"minutesSaved\", \"segmentCount\", \"viewCount\"]");
|
||||
public static final Route CHANGE_USERNAME = new Route(POST, "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}");
|
||||
public static final Route VOTE_ON_SEGMENT_QUALITY = new Route(POST, "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}");
|
||||
|
||||
private SBRoutes() {}
|
||||
}
|
Loading…
Reference in New Issue
Block a user