From c132670400e6bdf17c46b8d04d579fb49c3d2749 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:55:57 +0400 Subject: [PATCH] fix(YouTube - Hide Shorts components): Do not show Shorts suggestions in video player, if all hide Shorts options are enabled (#613) --- .../patches/components/ShortsFilter.java | 24 +++++++++++++++---- .../youtube/shared/NavigationBar.java | 17 +++++++------ 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java index bd5a32d7..039cb9d1 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/ShortsFilter.java @@ -220,20 +220,34 @@ public final class ShortsFilter extends Filter { } private static boolean shouldHideShortsFeedItems() { + final boolean hideHome = Settings.HIDE_SHORTS_HOME.get(); + final boolean hideSubscriptions = Settings.HIDE_SHORTS_SUBSCRIPTIONS.get(); + final boolean hideSearch = Settings.HIDE_SHORTS_SEARCH.get(); + + if (hideHome && hideSubscriptions && hideSearch) { + // Shorts suggestions can load in the background if a video is opened and + // then immediately minimized before any suggestions are loaded. + // In this state the player type will show minimized, which makes it not possible to + // distinguish between Shorts suggestions loading in the player and between + // scrolling thru search/home/subscription tabs while a player is minimized. + // + // To avoid this situation for users that never want to show Shorts (all hide Shorts options are enabled) + // then hide all Shorts everywhere including the Library history and Library playlists. + return true; + } + // Must check player type first, as search bar can be active behind the player. if (PlayerType.getCurrent().isMaximizedOrFullscreen()) { // For now, consider the under video results the same as the home feed. - return Settings.HIDE_SHORTS_HOME.get(); + return hideHome; } // Must check second, as search can be from any tab. if (NavigationBar.isSearchBarActive()) { - return Settings.HIDE_SHORTS_SEARCH.get(); + return hideSearch; } - // Avoid checking navigation button status if all other settings are off. - final boolean hideHome = Settings.HIDE_SHORTS_HOME.get(); - final boolean hideSubscriptions = Settings.HIDE_SHORTS_SUBSCRIPTIONS.get(); + // Avoid checking navigation button status if all other Shorts should show. if (!hideHome && !hideSubscriptions) { return false; } diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java b/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java index 58c2ec0b..5123e78d 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java @@ -197,6 +197,10 @@ public final class NavigationBar { */ public static void navigationTabSelected(View navButtonImageView, boolean isSelected) { try { + if (!isSelected) { + return; + } + NavigationButton button = viewToButtonMap.get(navButtonImageView); if (button == null) { // An unknown tab was selected. @@ -209,16 +213,11 @@ public final class NavigationBar { return; } - if (isSelected) { - NavigationButton.selectedNavigationButton = button; - Logger.printDebug(() -> "Changed to navigation button: " + button); + NavigationButton.selectedNavigationButton = button; + Logger.printDebug(() -> "Changed to navigation button: " + button); - // Release any threads waiting for the selected nav button. - releaseNavButtonLatch(); - } else if (NavigationButton.selectedNavigationButton == button) { - NavigationButton.selectedNavigationButton = null; - Logger.printDebug(() -> "Navigated away from button: " + button); - } + // Release any threads waiting for the selected nav button. + releaseNavButtonLatch(); } catch (Exception ex) { Logger.printException(() -> "navigationTabSelected failure", ex); }