diff --git a/integrations/java/pl/jakubweg/PlayerController.java b/integrations/java/pl/jakubweg/PlayerController.java index 74ca9cc66..ac613de90 100644 --- a/integrations/java/pl/jakubweg/PlayerController.java +++ b/integrations/java/pl/jakubweg/PlayerController.java @@ -95,7 +95,7 @@ public class PlayerController { Log.i(TAG, String.format("onCreate called with object %s on thread %s", o.toString(), Thread.currentThread().toString())); try { - setMillisecondMethod = o.getClass().getMethod("replaceMeWithsetMillisecondMethod", Long.TYPE); + setMillisecondMethod = o.getClass().getMethod("t", Long.TYPE); setMillisecondMethod.setAccessible(true); lastKnownVideoTime = 0; @@ -198,6 +198,12 @@ public class PlayerController { if (millis <= 0) return; //findAndSkipSegment(false); + if (millis == currentVideoLength) { + SponsorBlockUtils.hideShieldButton(); + SponsorBlockUtils.hideVoteButton(); + return; + } + SponsorSegment[] segments = sponsorSegmentsOfCurrentVideo; if (segments == null || segments.length == 0) return; @@ -274,6 +280,10 @@ public class PlayerController { setCurrentVideoTime(millis); } + public static long getCurrentVideoLength() { + return currentVideoLength; + } + public static long getLastKnownVideoTime() { return lastKnownVideoTime; } diff --git a/integrations/java/pl/jakubweg/ShieldButton.java b/integrations/java/pl/jakubweg/ShieldButton.java index eeadc5845..34a703d25 100644 --- a/integrations/java/pl/jakubweg/ShieldButton.java +++ b/integrations/java/pl/jakubweg/ShieldButton.java @@ -14,6 +14,8 @@ import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application; import java.lang.ref.WeakReference; import static fi.razerman.youtube.XGlobals.debug; +import static pl.jakubweg.PlayerController.getCurrentVideoLength; +import static pl.jakubweg.PlayerController.getLastKnownVideoTime; public class ShieldButton { static String TAG = "SHIELD"; @@ -79,6 +81,9 @@ public class ShieldButton { if (_youtubeControlsLayout == null || iView == null) return; if (visible && shouldBeShown()) { + if (getLastKnownVideoTime() == getCurrentVideoLength()) { + return; + } if (debug) { Log.d(TAG, "Fading in"); } diff --git a/integrations/java/pl/jakubweg/SponsorBlockUtils.java b/integrations/java/pl/jakubweg/SponsorBlockUtils.java index 6be97ccaa..990387c8f 100644 --- a/integrations/java/pl/jakubweg/SponsorBlockUtils.java +++ b/integrations/java/pl/jakubweg/SponsorBlockUtils.java @@ -158,10 +158,6 @@ public abstract class SponsorBlockUtils { new Thread(submitRunnable).start(); } }; - private static boolean isShieldShown = false; - private static boolean isVoteShown = false; - private static WeakReference sponsorBlockBtn = new WeakReference<>(null); - private static WeakReference votingBtn = new WeakReference<>(null); private static String messageToToast = ""; private static EditByHandSaveDialogListener editByHandSaveDialogListener = new EditByHandSaveDialogListener(); private static final DialogInterface.OnClickListener editByHandDialogListener = new DialogInterface.OnClickListener() { @@ -300,9 +296,7 @@ public abstract class SponsorBlockUtils { } public static void showShieldButton() { - if (isShieldShown) return; - isShieldShown = true; - View i = sponsorBlockBtn.get(); + View i = ShieldButton._shieldBtn.get(); if (i == null) return; i.setVisibility(VISIBLE); i.bringToFront(); @@ -311,17 +305,13 @@ public abstract class SponsorBlockUtils { } public static void hideShieldButton() { - if (!isShieldShown) return; - isShieldShown = false; - View i = sponsorBlockBtn.get(); + View i = ShieldButton._shieldBtn.get(); if (i != null) i.setVisibility(GONE); } public static void showVoteButton() { - if (isVoteShown) return; - isVoteShown = true; - View i = votingBtn.get(); + View i = VotingButton._votingButton.get(); if (i == null) return; i.setVisibility(VISIBLE); i.bringToFront(); @@ -330,9 +320,7 @@ public abstract class SponsorBlockUtils { } public static void hideVoteButton() { - if (!isVoteShown) return; - isVoteShown = false; - View i = votingBtn.get(); + View i = VotingButton._votingButton.get(); if (i != null) i.setVisibility(GONE); } @@ -445,7 +433,7 @@ public abstract class SponsorBlockUtils { if (v.getId() != shareBtnId || !/*SponsorBlockSettings.isAddNewSegmentEnabled*/false) return; // if (VERBOSE) // Log.d(TAG, "VISIBILITY CHANGED of view " + v); - ImageView sponsorBtn = sponsorBlockBtn.get(); + ImageView sponsorBtn = ShieldButton._shieldBtn.get(); if (sponsorBtn != null) { sponsorBtn.setVisibility(v.getVisibility()); } diff --git a/integrations/java/pl/jakubweg/VotingButton.java b/integrations/java/pl/jakubweg/VotingButton.java index 1b87eeb18..9795d1582 100644 --- a/integrations/java/pl/jakubweg/VotingButton.java +++ b/integrations/java/pl/jakubweg/VotingButton.java @@ -14,6 +14,8 @@ import com.google.android.apps.youtube.app.YouTubeTikTokRoot_Application; import java.lang.ref.WeakReference; import static fi.razerman.youtube.XGlobals.debug; +import static pl.jakubweg.PlayerController.getCurrentVideoLength; +import static pl.jakubweg.PlayerController.getLastKnownVideoTime; public class VotingButton { static String TAG = "VOTING"; @@ -79,6 +81,9 @@ public class VotingButton { if (_youtubeControlsLayout == null || iView == null) return; if (visible && shouldBeShown()) { + if (getLastKnownVideoTime() == getCurrentVideoLength()) { + return; + } if (debug) { Log.d(TAG, "Fading in"); }