mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-11 13:46:17 +00:00
fix(YouTube - SponsorBlock): Do not show undo skip if PiP is active (#5314)
This commit is contained in:
committed by
GitHub
parent
2b3419571f
commit
209a3a3626
@@ -44,6 +44,7 @@ import app.revanced.extension.youtube.sponsorblock.objects.SegmentCategory;
|
||||
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment;
|
||||
import app.revanced.extension.youtube.sponsorblock.requests.SBRequester;
|
||||
import app.revanced.extension.youtube.sponsorblock.ui.SponsorBlockViewController;
|
||||
import kotlin.Unit;
|
||||
|
||||
/**
|
||||
* Handles showing, scheduling, and skipping of all {@link SponsorSegment} for the current video.
|
||||
@@ -167,6 +168,30 @@ public class SegmentPlaybackController {
|
||||
*/
|
||||
private static WeakReference<Dialog> toastDialogRef = new WeakReference<>(null);
|
||||
|
||||
static {
|
||||
// Dismiss toast if app changes to PiP while undo skip is shown.
|
||||
PlayerType.getOnChange().addObserver((PlayerType type) -> {
|
||||
if (type == PlayerType.WATCH_WHILE_PICTURE_IN_PICTURE && dismissUndoToast()) {
|
||||
Logger.printDebug(() -> "Dismissed undo toast as playback is PiP");
|
||||
}
|
||||
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @return If the toast was on screen and is now dismissed.
|
||||
*/
|
||||
private static boolean dismissUndoToast() {
|
||||
Dialog toastDialog = toastDialogRef.get();
|
||||
if (toastDialog != null && toastDialog.isShowing()) {
|
||||
toastDialog.dismiss();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The adjusted duration to show the skip button, in milliseconds.
|
||||
*/
|
||||
@@ -700,6 +725,11 @@ public class SegmentPlaybackController {
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlayerType.getCurrent() == PlayerType.WATCH_WHILE_PICTURE_IN_PICTURE) {
|
||||
Logger.printDebug(() -> "Not showing autoskip toast as playback is PiP");
|
||||
return;
|
||||
}
|
||||
|
||||
if (toastSegmentSkipped == null || undoAutoSkipRangeToast == null) {
|
||||
// Video was changed immediately after skipping segment.
|
||||
Logger.printDebug(() -> "Ignoring old scheduled show toast");
|
||||
@@ -709,9 +739,7 @@ public class SegmentPlaybackController {
|
||||
? toastSegmentSkipped.getSkippedToastText()
|
||||
: str("revanced_sb_skipped_multiple_segments");
|
||||
|
||||
showToastShortWithTapAction(message, undoAutoSkipRangeToast);
|
||||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "showSkippedSegmentToast failure", ex);
|
||||
showAutoSkipToast(message, undoAutoSkipRangeToast);
|
||||
} finally {
|
||||
toastNumberOfSegmentsSkipped = 0;
|
||||
toastSegmentSkipped = null;
|
||||
@@ -719,7 +747,7 @@ public class SegmentPlaybackController {
|
||||
}, delayToToastMilliseconds);
|
||||
}
|
||||
|
||||
private static void showToastShortWithTapAction(String messageToToast, Range<Long> rangeToUndo) {
|
||||
private static void showAutoSkipToast(String messageToToast, Range<Long> rangeToUndo) {
|
||||
Objects.requireNonNull(messageToToast);
|
||||
Utils.verifyOnMainThread();
|
||||
|
||||
@@ -816,10 +844,8 @@ public class SegmentPlaybackController {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
|
||||
}
|
||||
|
||||
Dialog priorDialog = toastDialogRef.get();
|
||||
if (priorDialog != null && priorDialog.isShowing()) {
|
||||
Logger.printDebug(() -> "Removing previous skip toast that is still on screen: " + priorDialog);
|
||||
priorDialog.dismiss();
|
||||
if (dismissUndoToast()) {
|
||||
Logger.printDebug(() -> "Dismissed previous skip toast that was still on screen");
|
||||
}
|
||||
toastDialogRef = new WeakReference<>(dialog);
|
||||
|
||||
|
||||
@@ -1029,12 +1029,12 @@ This feature works best with a video quality of 720p or lower and when using a v
|
||||
<string name="revanced_sb_enable_auto_hide_skip_segment_button_sum_on">Skip button hides after a few seconds</string>
|
||||
<string name="revanced_sb_enable_auto_hide_skip_segment_button_sum_off">Skip button is shown for the entire segment</string>
|
||||
<string name="revanced_sb_auto_hide_skip_button_duration">Skip button duration</string>
|
||||
<string name="revanced_sb_auto_hide_skip_button_duration_sum">How long the auto hide skip and skip to highlight buttons are shown</string>
|
||||
<string name="revanced_sb_auto_hide_skip_button_duration_sum">How long to show the skip and skip to highlight buttons before automatically hiding</string>
|
||||
<string name="revanced_sb_general_skiptoast">Show undo skip toast</string>
|
||||
<string name="revanced_sb_general_skiptoast_sum_on">Toast is shown when a segment is automatically skipped. Tap the toast notification to undo the skip</string>
|
||||
<string name="revanced_sb_general_skiptoast_sum_off">Toast is not shown</string>
|
||||
<string name="revanced_sb_toast_on_skip_duration">Skip toast duration</string>
|
||||
<string name="revanced_sb_toast_on_skip_duration_sum">How long the skip toast notification is shown</string>
|
||||
<string name="revanced_sb_toast_on_skip_duration_sum">How long to show the undo skip toast</string>
|
||||
<string name="revanced_sb_duration_1s">1 second</string>
|
||||
<string name="revanced_sb_duration_2s">2 seconds</string>
|
||||
<string name="revanced_sb_duration_3s">3 seconds</string>
|
||||
|
||||
Reference in New Issue
Block a user