highlight locked segments in the vote menu

This commit is contained in:
caneleex 2022-01-17 08:51:04 +01:00
parent 92d58b7963
commit 95f54b11f1
3 changed files with 24 additions and 9 deletions

View File

@ -72,6 +72,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");
@ -212,10 +213,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 (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)
@ -416,7 +424,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;
@ -651,14 +659,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;
}
}

View File

@ -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 +
'}';
}

View File

@ -54,10 +54,11 @@ public class Requester {
long end = (long) (segment.getDouble(1) * 1000);
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);
}
}