From 27c6fa88ab400bca141ca4e7d0ef70a13e0a0742 Mon Sep 17 00:00:00 2001 From: caneleex Date: Mon, 17 Jan 2022 08:51:04 +0100 Subject: [PATCH] highlight locked segments in the vote menu --- .../java/pl/jakubweg/SponsorBlockUtils.java | 25 +++++++++++++------ .../pl/jakubweg/objects/SponsorSegment.java | 5 +++- .../java/pl/jakubweg/requests/Requester.java | 3 ++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java index 8ac1e0a6..e5477990 100644 --- a/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java +++ b/app/src/main/java/pl/jakubweg/SponsorBlockUtils.java @@ -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("%s", 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; } } diff --git a/app/src/main/java/pl/jakubweg/objects/SponsorSegment.java b/app/src/main/java/pl/jakubweg/objects/SponsorSegment.java index 1819bba7..2fed40a3 100644 --- a/app/src/main/java/pl/jakubweg/objects/SponsorSegment.java +++ b/app/src/main/java/pl/jakubweg/objects/SponsorSegment.java @@ -7,12 +7,14 @@ public class SponsorSegment implements Comparable { 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 { "start=" + start + ", end=" + end + ", category='" + category + '\'' + + ", locked=" + isLocked + '}'; } diff --git a/app/src/main/java/pl/jakubweg/requests/Requester.java b/app/src/main/java/pl/jakubweg/requests/Requester.java index 2b7884c1..d268db6e 100644 --- a/app/src/main/java/pl/jakubweg/requests/Requester.java +++ b/app/src/main/java/pl/jakubweg/requests/Requester.java @@ -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); } }