refactor: remove reduntant check for shorts_playing (#150)

This commit is contained in:
inotia00 2022-09-27 13:54:32 +09:00 committed by GitHub
parent 04bbe259cb
commit 73b40595c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 4 additions and 42 deletions

View File

@ -108,7 +108,6 @@ public enum SettingsEnum {
SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN), SB_SHOW_BROWSER_BUTTON("sb-browser-button", false, SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.BOOLEAN),
SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING); SB_API_URL("sb-api-url", "https://sponsor.ajay.app/api/", SharedPrefHelper.SharedPrefNames.SPONSOR_BLOCK, ReturnType.STRING);
public static boolean shorts_playing = false;
private final String path; private final String path;
private final Object defaultValue; private final Object defaultValue;
private final SharedPrefHelper.SharedPrefNames sharedPref; private final SharedPrefHelper.SharedPrefNames sharedPref;

View File

@ -49,6 +49,8 @@ public class PlayerController {
private static float sponsorBarThickness = 2f; private static float sponsorBarThickness = 2f;
private static TimerTask skipSponsorTask = null; private static TimerTask skipSponsorTask = null;
public static boolean shorts_playing = false;
public static String getCurrentVideoId() { public static String getCurrentVideoId() {
return currentVideoId; return currentVideoId;
} }
@ -87,9 +89,6 @@ public class PlayerController {
* Called when creating some kind of youtube internal player controlled, every time when new video starts to play * Called when creating some kind of youtube internal player controlled, every time when new video starts to play
*/ */
public static void onCreate(final Object o) { public static void onCreate(final Object o) {
if (SettingsEnum.shorts_playing) return;
// "Plugin.printStackTrace();
if (o == null) { if (o == null) {
LogHelper.printException(PlayerController.class, "onCreate called with null object"); LogHelper.printException(PlayerController.class, "onCreate called with null object");
@ -117,8 +116,9 @@ public class PlayerController {
public static void executeDownloadSegments(String videoId) { public static void executeDownloadSegments(String videoId) {
videoHasSegments = false; videoHasSegments = false;
timeWithoutSegments = ""; timeWithoutSegments = "";
if (Whitelist.isChannelSBWhitelisted()) if (Whitelist.isChannelSBWhitelisted() || shorts_playing) {
return; return;
}
SponsorSegment[] segments = SBRequester.getSegments(videoId); SponsorSegment[] segments = SBRequester.getSegments(videoId);
Arrays.sort(segments); Arrays.sort(segments);
@ -134,8 +134,6 @@ public class PlayerController {
* Called when it's time to update the UI with new second, about once per second, only when playing, also in background * Called when it's time to update the UI with new second, about once per second, only when playing, also in background
*/ */
public static void setCurrentVideoTime(long millis) { public static void setCurrentVideoTime(long millis) {
if (SettingsEnum.shorts_playing) return;
LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis); LogHelper.debug(PlayerController.class, "setCurrentVideoTime: current video time: " + millis);
VideoInformation.lastKnownVideoTime = millis; VideoInformation.lastKnownVideoTime = millis;
if (!SettingsEnum.SB_ENABLED.getBoolean()) return; if (!SettingsEnum.SB_ENABLED.getBoolean()) return;
@ -220,8 +218,6 @@ public class PlayerController {
* Called very high frequency (once every about 100ms), also in background. It sometimes triggers when a video is paused (couple times in the row with the same value) * Called very high frequency (once every about 100ms), also in background. It sometimes triggers when a video is paused (couple times in the row with the same value)
*/ */
public static void setCurrentVideoTimeHighPrecision(final long millis) { public static void setCurrentVideoTimeHighPrecision(final long millis) {
if (SettingsEnum.shorts_playing) return;
if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) { if ((millis < lastKnownVideoTime && lastKnownVideoTime >= currentVideoLength) || millis == 0) {
SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again SponsorBlockUtils.showShieldButton(); // skipping from end to the video will show the buttons again
SponsorBlockUtils.showVoteButton(); SponsorBlockUtils.showVoteButton();
@ -245,16 +241,12 @@ public class PlayerController {
* Called before onDraw method on time bar object, sets video length in millis * Called before onDraw method on time bar object, sets video length in millis
*/ */
public static void setVideoLength(final long length) { public static void setVideoLength(final long length) {
if (SettingsEnum.shorts_playing) return;
LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length); LogHelper.debug(PlayerController.class, "setVideoLength: length=" + length);
currentVideoLength = length; currentVideoLength = length;
} }
public static void setSponsorBarAbsoluteLeft(final Rect rect) { public static void setSponsorBarAbsoluteLeft(final Rect rect) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarAbsoluteLeft(rect.left); setSponsorBarAbsoluteLeft(rect.left);
} }
@ -265,8 +257,6 @@ public class PlayerController {
} }
public static void setSponsorBarRect(final Object self) { public static void setSponsorBarRect(final Object self) {
if (SettingsEnum.shorts_playing || self == null) return;
try { try {
Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect"); Field field = self.getClass().getDeclaredField("replaceMeWithsetSponsorBarRect");
field.setAccessible(true); field.setAccessible(true);
@ -281,8 +271,6 @@ public class PlayerController {
} }
public static void setSponsorBarAbsoluteRight(final Rect rect) { public static void setSponsorBarAbsoluteRight(final Rect rect) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarAbsoluteRight(rect.right); setSponsorBarAbsoluteRight(rect.right);
} }
@ -293,8 +281,6 @@ public class PlayerController {
} }
public static void setSponsorBarThickness(final int thickness) { public static void setSponsorBarThickness(final int thickness) {
if (SettingsEnum.shorts_playing) return;
setSponsorBarThickness((float) thickness); setSponsorBarThickness((float) thickness);
} }
@ -312,8 +298,6 @@ public class PlayerController {
public static void addSkipSponsorView15(final View view) { public static void addSkipSponsorView15(final View view) {
if (SettingsEnum.shorts_playing) return;
playerActivity = new WeakReference<>((Activity) view.getContext()); playerActivity = new WeakReference<>((Activity) view.getContext());
LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString()); LogHelper.debug(PlayerController.class, "addSkipSponsorView15: view=" + view.toString());
@ -339,8 +323,6 @@ public class PlayerController {
* Called when it's time to draw time bar * Called when it's time to draw time bar
*/ */
public static void drawSponsorTimeBars(final Canvas canvas, final float posY) { public static void drawSponsorTimeBars(final Canvas canvas, final float posY) {
if (SettingsEnum.shorts_playing) return;
if (sponsorBarThickness < 0.1) return; if (sponsorBarThickness < 0.1) return;
if (sponsorSegmentsOfCurrentVideo == null) return; if (sponsorSegmentsOfCurrentVideo == null) return;

View File

@ -28,8 +28,6 @@ public class ShieldButton {
static boolean isShowing; static boolean isShowing;
public static void initialize(Object viewStub) { public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(ShieldButton.class, "initializing shield button"); LogHelper.debug(ShieldButton.class, "initializing shield button");
@ -64,14 +62,10 @@ public class ShieldButton {
} }
public static void changeVisibilityNegatedImmediate(boolean visible) { public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(!visible, true); changeVisibility(!visible, true);
} }
public static void changeVisibility(boolean visible) { public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(visible, false); changeVisibility(visible, false);
} }

View File

@ -403,8 +403,6 @@ public abstract class SponsorBlockUtils {
} }
public static String appendTimeWithoutSegments(String totalTime) { public static String appendTimeWithoutSegments(String totalTime) {
if (SettingsEnum.shorts_playing) return totalTime;
if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) { if (videoHasSegments && (SettingsEnum.SB_ENABLED.getBoolean() && SettingsEnum.SB_SHOW_TIME_WITHOUT_SEGMENTS.getBoolean()) && !TextUtils.isEmpty(totalTime) && getCurrentVideoLength() > 1) {
if (timeWithoutSegments.isEmpty()) { if (timeWithoutSegments.isEmpty()) {
timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo); timeWithoutSegments = getTimeWithoutSegments(sponsorSegmentsOfCurrentVideo);

View File

@ -27,8 +27,6 @@ public class VotingButton {
static boolean isShowing; static boolean isShowing;
public static void initialize(Object viewStub) { public static void initialize(Object viewStub) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(VotingButton.class, "initializing voting button"); LogHelper.debug(VotingButton.class, "initializing voting button");
_youtubeControlsLayout = (RelativeLayout) viewStub; _youtubeControlsLayout = (RelativeLayout) viewStub;
@ -62,14 +60,10 @@ public class VotingButton {
} }
public static void changeVisibilityNegatedImmediate(boolean visible) { public static void changeVisibilityNegatedImmediate(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(!visible, true); changeVisibility(!visible, true);
} }
public static void changeVisibility(boolean visible) { public static void changeVisibility(boolean visible) {
if (SettingsEnum.shorts_playing) return;
changeVisibility(visible, false); changeVisibility(visible, false);
} }

View File

@ -23,8 +23,6 @@ public class SponsorBlockView {
static boolean shouldShowOnPlayerType = true; static boolean shouldShowOnPlayerType = true;
public static void initialize(Object viewGroup) { public static void initialize(Object viewGroup) {
if (SettingsEnum.shorts_playing) return;
try { try {
LogHelper.debug(SponsorBlockView.class, "initializing"); LogHelper.debug(SponsorBlockView.class, "initializing");

View File

@ -1,6 +1,5 @@
package app.revanced.integrations.videoplayer; package app.revanced.integrations.videoplayer;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
public class VideoInformation { public class VideoInformation {
@ -15,8 +14,6 @@ public class VideoInformation {
// Call hook in the YT code when the video changes // Call hook in the YT code when the video changes
public static void setCurrentVideoId(final String videoId) { public static void setCurrentVideoId(final String videoId) {
if (SettingsEnum.shorts_playing) return;
if (videoId == null) { if (videoId == null) {
LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId); LogHelper.debug(VideoInformation.class, "setCurrentVideoId - new id was null - currentVideoId was" + currentVideoId);
clearInformation(true); clearInformation(true);