diff --git a/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java b/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java index 7117b60e87..f9174ee09f 100644 --- a/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/ReturnYouTubeDislikePatch.java @@ -235,8 +235,9 @@ public static CharSequence onLithoTextLoaded(@NonNull Object conversionContext, } ReturnYouTubeDislike videoData = lastLithoShortsVideoData; if (videoData == null) { - // Somehow the litho video id filter did not detect the video id. - LogHelper.printDebug(() -> "Error: Litho video data is null, but it should not be"); + // The Shorts litho video id filter did not detect the video id. + // This is normal if in incognito mode, but otherwise is not normal. + LogHelper.printDebug(() -> "Cannot modify Shorts litho span, data is null"); return original; } // Use the correct dislikes data after voting. @@ -437,7 +438,10 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith if (!SettingsEnum.RYD_ENABLED.getBoolean()) return; PlayerType currentPlayerType = PlayerType.getCurrent(); - if (currentPlayerType.isNoneOrHidden() && !SettingsEnum.RYD_SHORTS.getBoolean()) { + final boolean isNoneHiddenOrSlidingMinimized = currentPlayerType.isNoneHiddenOrSlidingMinimized(); + if (isNoneHiddenOrSlidingMinimized && !SettingsEnum.RYD_SHORTS.getBoolean()) { + // Must clear here, otherwise the wrong data can be used for a minimized regular video. + currentVideoData = null; return; } @@ -450,7 +454,7 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith // Litho filter did not detect the video id. App is in incognito mode, // or the proto buffer structure was changed and the video id is no longer present. // Must clear both currently playing and last litho data otherwise the - // next regular video may use the wrong data + // next regular video may use the wrong data. LogHelper.printDebug(() -> "Litho filter did not find any video ids"); currentVideoData = null; lastLithoShortsVideoData = null; @@ -468,6 +472,12 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith return; } currentVideoData = ReturnYouTubeDislike.getFetchForVideoId(videoId); + // Pre-emptively set the data to short status. + // Required to prevent Shorts data from being used on a minimized video in incognito mode. + if (isNoneHiddenOrSlidingMinimized) { + // Short is playing with a regular video minimized. + currentVideoData.setVideoIdIsShort(true); + } } LogHelper.printDebug(() -> "New video id: " + videoId + " playerType: " + currentPlayerType @@ -475,14 +485,17 @@ public static void newVideoLoaded(@Nullable String videoId, boolean isShortsLith // Current video id hook can be called out of order with the non litho Shorts text view hook. // Must manually update again here. - updateOnScreenShortsTextViews(true); + if (!isShortsLithoVideoId && isNoneHiddenOrSlidingMinimized) { + updateOnScreenShortsTextViews(true); + } } catch (Exception ex) { LogHelper.printException(() -> "newVideoLoaded failure", ex); } } - private static boolean videoIdIsSame(@Nullable ReturnYouTubeDislike fetch, String videoId) { - return fetch != null && fetch.getVideoId().equals(videoId); + private static boolean videoIdIsSame(@Nullable ReturnYouTubeDislike fetch, @Nullable String videoId) { + return (fetch == null && videoId == null) + || (fetch != null && fetch.getVideoId().equals(videoId)); } /** @@ -511,10 +524,13 @@ public static void sendVote(int vote) { if (v.value == vote) { videoData.sendVote(v); - if (isNoneHiddenOrMinimized && lastLithoShortsVideoData != null) { - lithoShortsShouldUseCurrentData = true; + if (isNoneHiddenOrMinimized) { + if (lastLithoShortsVideoData != null) { + lithoShortsShouldUseCurrentData = true; + } + updateOldUIDislikesTextView(); } - updateOldUIDislikesTextView(); + return; } } diff --git a/app/src/main/java/app/revanced/integrations/patches/components/ReturnYouTubeDislikeFilterPatch.java b/app/src/main/java/app/revanced/integrations/patches/components/ReturnYouTubeDislikeFilterPatch.java index 9ae60b8e22..b52fd486fc 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/ReturnYouTubeDislikeFilterPatch.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/ReturnYouTubeDislikeFilterPatch.java @@ -25,7 +25,7 @@ * that makes the value of {@link VideoInformation#getVideoId()} and {@link VideoInformation#getPlayerResponseVideoId()} * unreliable to determine which video id a Shorts litho span belongs to. * - * But the correct video id does appear in the protobuffer just before any litho span is created. + * But the correct video id does appear in the protobuffer just before a Shorts litho span is created. * * Once a way to asynchronously update litho text is found, this strategy will no longer be needed. */ @@ -91,6 +91,8 @@ public boolean isFiltered(@Nullable String identifier, String path, byte[] proto String matchedVideoId = findVideoId(protobufBufferArray); // Matched video will be null if in incognito mode. // Must pass a null id to correctly clear out the current video data. + // Otherwise if a Short is opened in non-incognito, then incognito is enabled and another Short is opened, + // the new incognito Short will show the old prior data. ReturnYouTubeDislikePatch.newVideoLoaded(matchedVideoId, true); } diff --git a/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java b/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java index 7c8175a836..da8cd810a9 100644 --- a/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java +++ b/app/src/main/java/app/revanced/integrations/returnyoutubedislike/ReturnYouTubeDislike.java @@ -142,7 +142,6 @@ public enum Vote { /** * If this instance was previously used for a Short. */ - @Nullable @GuardedBy("this") private boolean isShort; @@ -421,7 +420,6 @@ public String getVideoId() { /** * Pre-emptively set this as a Short. - * Should only be used immediately after creation of this instance. */ public synchronized void setVideoIdIsShort(boolean isShort) { this.isShort = isShort; @@ -475,11 +473,11 @@ private Spanned waitForFetchAndUpdateReplacementSpan(@NonNull Spanned original, if (originalDislikeSpan != null && replacementLikeDislikeSpan != null) { if (spansHaveEqualTextAndColor(original, replacementLikeDislikeSpan)) { - LogHelper.printDebug(() -> "Ignoring previously created dislikes span"); + LogHelper.printDebug(() -> "Ignoring previously created dislikes span of data: " + videoId); return original; } if (spansHaveEqualTextAndColor(original, originalDislikeSpan)) { - LogHelper.printDebug(() -> "Replacing span with previously created dislike span"); + LogHelper.printDebug(() -> "Replacing span with previously created dislike span of data: " + videoId); return replacementLikeDislikeSpan; } } @@ -518,7 +516,7 @@ public void sendVote(@NonNull Vote vote) { if (isShort != PlayerType.getCurrent().isNoneOrHidden()) { // Shorts was loaded with regular video present, then Shorts was closed. // and then user voted on the now visible original video. - // Cannot send a vote, because the loaded videoId is for the wrong video. + // Cannot send a vote, because this instance is for the wrong video. ReVancedUtils.showToastLong(str("revanced_ryd_failure_ryd_enabled_while_playing_video_then_user_voted")); return; } diff --git a/app/src/main/java/app/revanced/integrations/shared/PlayerType.kt b/app/src/main/java/app/revanced/integrations/shared/PlayerType.kt index a8dec9ccec..8833d0a0a9 100644 --- a/app/src/main/java/app/revanced/integrations/shared/PlayerType.kt +++ b/app/src/main/java/app/revanced/integrations/shared/PlayerType.kt @@ -26,7 +26,9 @@ enum class PlayerType { WATCH_WHILE_SLIDING_MAXIMIZED_FULLSCREEN, WATCH_WHILE_SLIDING_MINIMIZED_MAXIMIZED, /** - * When opening a short while a regular video is minimized, the type can momentarily be this. + * Player is either sliding to [HIDDEN] state because a Short was opened while a regular video is on screen. + * OR + * The user has swiped a minimized player away to be closed (and no Short is being opened). */ WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED, WATCH_WHILE_SLIDING_FULLSCREEN_DISMISSED, @@ -84,20 +86,32 @@ enum class PlayerType { return this == NONE || this == HIDDEN } + /** + * Check if the current player type is + * [NONE], [HIDDEN], [WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED]. + * + * Useful to check if a Short is being played, and usually covers all use cases + * except for some hooks when spoofing to an old version (where the type can be [WATCH_WHILE_MINIMIZED]. + * + * @return If nothing, a Short, or a regular video is sliding off screen to a dismissed or hidden state. + */ + fun isNoneHiddenOrSlidingMinimized(): Boolean { + return isNoneOrHidden() || this == WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED + } + /** * Check if the current player type is * [NONE], [HIDDEN], [WATCH_WHILE_MINIMIZED], [WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED]. * * Useful to check if a Short is being played, - * although will return false positive if a regular video is opened and minimized (and no short is playing). + * although will return false positive if a regular video is + * opened and minimized (and a Short is not playing or being opened). * * @return If nothing, a Short, * or a regular video is minimized video or sliding off screen to a dismissed or hidden state. */ fun isNoneHiddenOrMinimized(): Boolean { - return this == NONE || this == HIDDEN - || this == WATCH_WHILE_MINIMIZED - || this == WATCH_WHILE_SLIDING_MINIMIZED_DISMISSED + return isNoneHiddenOrSlidingMinimized() || this == WATCH_WHILE_MINIMIZED } } \ No newline at end of file