Skip to content

Commit 18af8de

Browse files
fix(YouTube - SponsorBlock): Do not show undo skip if PiP is active (#5314)
1 parent f02695e commit 18af8de

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

extensions/youtube/src/main/java/app/revanced/extension/youtube/sponsorblock/SegmentPlaybackController.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import app.revanced.extension.youtube.sponsorblock.objects.SponsorSegment;
4545
import app.revanced.extension.youtube.sponsorblock.requests.SBRequester;
4646
import app.revanced.extension.youtube.sponsorblock.ui.SponsorBlockViewController;
47+
import kotlin.Unit;
4748

4849
/**
4950
* Handles showing, scheduling, and skipping of all {@link SponsorSegment} for the current video.
@@ -167,6 +168,30 @@ public enum SponsorBlockDuration {
167168
*/
168169
private static WeakReference<Dialog> toastDialogRef = new WeakReference<>(null);
169170

171+
static {
172+
// Dismiss toast if app changes to PiP while undo skip is shown.
173+
PlayerType.getOnChange().addObserver((PlayerType type) -> {
174+
if (type == PlayerType.WATCH_WHILE_PICTURE_IN_PICTURE && dismissUndoToast()) {
175+
Logger.printDebug(() -> "Dismissed undo toast as playback is PiP");
176+
}
177+
178+
return Unit.INSTANCE;
179+
});
180+
}
181+
182+
/**
183+
* @return If the toast was on screen and is now dismissed.
184+
*/
185+
private static boolean dismissUndoToast() {
186+
Dialog toastDialog = toastDialogRef.get();
187+
if (toastDialog != null && toastDialog.isShowing()) {
188+
toastDialog.dismiss();
189+
return true;
190+
}
191+
192+
return false;
193+
}
194+
170195
/**
171196
* @return The adjusted duration to show the skip button, in milliseconds.
172197
*/
@@ -700,6 +725,11 @@ private static void showSkippedSegmentToast(SponsorSegment segment) {
700725
return;
701726
}
702727

728+
if (PlayerType.getCurrent() == PlayerType.WATCH_WHILE_PICTURE_IN_PICTURE) {
729+
Logger.printDebug(() -> "Not showing autoskip toast as playback is PiP");
730+
return;
731+
}
732+
703733
if (toastSegmentSkipped == null || undoAutoSkipRangeToast == null) {
704734
// Video was changed immediately after skipping segment.
705735
Logger.printDebug(() -> "Ignoring old scheduled show toast");
@@ -709,17 +739,15 @@ private static void showSkippedSegmentToast(SponsorSegment segment) {
709739
? toastSegmentSkipped.getSkippedToastText()
710740
: str("revanced_sb_skipped_multiple_segments");
711741

712-
showToastShortWithTapAction(message, undoAutoSkipRangeToast);
713-
} catch (Exception ex) {
714-
Logger.printException(() -> "showSkippedSegmentToast failure", ex);
742+
showAutoSkipToast(message, undoAutoSkipRangeToast);
715743
} finally {
716744
toastNumberOfSegmentsSkipped = 0;
717745
toastSegmentSkipped = null;
718746
}
719747
}, delayToToastMilliseconds);
720748
}
721749

722-
private static void showToastShortWithTapAction(String messageToToast, Range<Long> rangeToUndo) {
750+
private static void showAutoSkipToast(String messageToToast, Range<Long> rangeToUndo) {
723751
Objects.requireNonNull(messageToToast);
724752
Utils.verifyOnMainThread();
725753

@@ -816,10 +844,8 @@ public void onAnimationRepeat(Animation animation) { }
816844
window.addFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
817845
}
818846

819-
Dialog priorDialog = toastDialogRef.get();
820-
if (priorDialog != null && priorDialog.isShowing()) {
821-
Logger.printDebug(() -> "Removing previous skip toast that is still on screen: " + priorDialog);
822-
priorDialog.dismiss();
847+
if (dismissUndoToast()) {
848+
Logger.printDebug(() -> "Dismissed previous skip toast that was still on screen");
823849
}
824850
toastDialogRef = new WeakReference<>(dialog);
825851

patches/src/main/resources/addresources/values/strings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,12 @@ This feature works best with a video quality of 720p or lower and when using a v
10291029
<string name="revanced_sb_enable_auto_hide_skip_segment_button_sum_on">Skip button hides after a few seconds</string>
10301030
<string name="revanced_sb_enable_auto_hide_skip_segment_button_sum_off">Skip button is shown for the entire segment</string>
10311031
<string name="revanced_sb_auto_hide_skip_button_duration">Skip button duration</string>
1032-
<string name="revanced_sb_auto_hide_skip_button_duration_sum">How long the auto hide skip and skip to highlight buttons are shown</string>
1032+
<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>
10331033
<string name="revanced_sb_general_skiptoast">Show undo skip toast</string>
10341034
<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>
10351035
<string name="revanced_sb_general_skiptoast_sum_off">Toast is not shown</string>
10361036
<string name="revanced_sb_toast_on_skip_duration">Skip toast duration</string>
1037-
<string name="revanced_sb_toast_on_skip_duration_sum">How long the skip toast notification is shown</string>
1037+
<string name="revanced_sb_toast_on_skip_duration_sum">How long to show the undo skip toast</string>
10381038
<string name="revanced_sb_duration_1s">1 second</string>
10391039
<string name="revanced_sb_duration_2s">2 seconds</string>
10401040
<string name="revanced_sb_duration_3s">3 seconds</string>

0 commit comments

Comments
 (0)