From fedace02fd5c443ef37dcf77253438b041f4c3f9 Mon Sep 17 00:00:00 2001 From: nullptr <107796137+johnconner122@users.noreply.github.com> Date: Sat, 6 Apr 2024 21:41:50 +0300 Subject: [PATCH] feat(YouTube - Hide layout components): Add option to hide horizontal shelves (#598) Co-authored-by: oSumAtrIX Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> --- .../patches/HideBreakingNewsPatch.java | 29 ------------------- .../components/LayoutComponentsFilter.java | 28 ++++++++++++++++-- .../youtube/settings/Settings.java | 3 +- 3 files changed, 28 insertions(+), 32 deletions(-) delete mode 100644 app/src/main/java/app/revanced/integrations/youtube/patches/HideBreakingNewsPatch.java diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/HideBreakingNewsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/HideBreakingNewsPatch.java deleted file mode 100644 index bd6d89fa..00000000 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/HideBreakingNewsPatch.java +++ /dev/null @@ -1,29 +0,0 @@ -package app.revanced.integrations.youtube.patches; - -import android.view.View; - -import app.revanced.integrations.youtube.patches.spoof.SpoofAppVersionPatch; -import app.revanced.integrations.youtube.settings.Settings; -import app.revanced.integrations.shared.Utils; - -@SuppressWarnings("unused") -public class HideBreakingNewsPatch { - - /** - * When spoofing to app versions 17.31.00 and older, the watch history preview bar uses - * the same layout components as the breaking news shelf. - * - * Breaking news does not appear to be present in these older versions anyways. - */ - private static final boolean isSpoofingOldVersionWithHorizontalCardListWatchHistory = - SpoofAppVersionPatch.isSpoofingToLessThan("18.01.00"); - - /** - * Injection point. - */ - public static void hideBreakingNews(View view) { - if (!Settings.HIDE_BREAKING_NEWS.get() - || isSpoofingOldVersionWithHorizontalCardListWatchHistory) return; - Utils.hideViewByLayoutParams(view); - } -} diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java index 8c52c2d8..a22ff004 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/components/LayoutComponentsFilter.java @@ -35,6 +35,7 @@ public final class LayoutComponentsFilter extends Filter { private final StringFilterGroup compactChannelBarInner; private final StringFilterGroup compactChannelBarInnerButton; private final ByteArrayFilterGroup joinMembershipButton; + private final StringFilterGroup horizontalShelves; static { mixPlaylistsExceptions.addPatterns( @@ -43,7 +44,6 @@ public final class LayoutComponentsFilter extends Filter { ); } - @RequiresApi(api = Build.VERSION_CODES.N) public LayoutComponentsFilter() { exceptions.addPatterns( @@ -237,6 +237,12 @@ public final class LayoutComponentsFilter extends Filter { "endorsement_header_footer" ); + horizontalShelves = new StringFilterGroup( + Settings.HIDE_HORIZONTAL_SHELVES, + "horizontal_video_shelf.eml", + "horizontal_shelf.eml" + ); + addPathCallbacks( expandableMetadata, inFeedSurvey, @@ -263,7 +269,8 @@ public final class LayoutComponentsFilter extends Filter { timedReactions, imageShelf, channelMemberShelf, - forYouShelf + forYouShelf, + horizontalShelves ); } @@ -279,7 +286,9 @@ public final class LayoutComponentsFilter extends Filter { // The groups are excluded from the filter due to the exceptions list below. // Filter them separately here. if (matchedGroup == notifyMe || matchedGroup == inFeedSurvey || matchedGroup == expandableMetadata) + { return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex); + } if (exceptions.matches(path)) return false; // Exceptions are not filtered. @@ -298,6 +307,10 @@ public final class LayoutComponentsFilter extends Filter { // TODO: This also hides the feed Shorts shelf header if (matchedGroup == searchResultShelfHeader && contentIndex != 0) return false; + if (contentIndex == 0 && matchedGroup == horizontalShelves && hideShelves()) { + return super.isFiltered(path, identifier, protobufBufferArray, matchedGroup, contentType, contentIndex); + } + return super.isFiltered(identifier, path, protobufBufferArray, matchedGroup, contentType, contentIndex); } @@ -346,4 +359,15 @@ public final class LayoutComponentsFilter extends Filter { Utils.hideViewByLayoutParams(view); } } + + private static boolean hideShelves() { + // Only filter if the library tab is not selected. + // This check is important as the shelf layout is used for the library tab playlists. + return !NavigationBar.NavigationButton.libraryOrYouTabIsSelected() + // But if the player is opened while library is selected, + // then still filter any recommendations below the player. + || PlayerType.getCurrent().isMaximizedOrFullscreen() + // Or if the search is active while library is selected, then also filter. + || NavigationBar.isSearchBarActive(); + } } diff --git a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java index 714306f4..e8261ff3 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java +++ b/app/src/main/java/app/revanced/integrations/youtube/settings/Settings.java @@ -55,6 +55,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_SELF_SPONSOR = new BooleanSetting("revanced_hide_self_sponsor_ads", TRUE); public static final BooleanSetting HIDE_VIDEO_ADS = new BooleanSetting("revanced_hide_video_ads", TRUE, true); public static final BooleanSetting HIDE_WEB_SEARCH_RESULTS = new BooleanSetting("revanced_hide_web_search_results", TRUE); + // Layout public static final EnumSetting ALT_THUMBNAIL_HOME = new EnumSetting<>("revanced_alt_thumbnail_home", ThumbnailOption.ORIGINAL); public static final EnumSetting ALT_THUMBNAIL_SUBSCRIPTIONS = new EnumSetting<>("revanced_alt_thumbnail_subscription", ThumbnailOption.ORIGINAL); @@ -76,7 +77,7 @@ public class Settings extends BaseSettings { public static final BooleanSetting HIDE_ALBUM_CARDS = new BooleanSetting("revanced_hide_album_cards", FALSE, true); public static final BooleanSetting HIDE_ARTIST_CARDS = new BooleanSetting("revanced_hide_artist_cards", FALSE); public static final BooleanSetting HIDE_AUTOPLAY_BUTTON = new BooleanSetting("revanced_hide_autoplay_button", TRUE, true); - public static final BooleanSetting HIDE_BREAKING_NEWS = new BooleanSetting("revanced_hide_breaking_news", TRUE, true); + public static final BooleanSetting HIDE_HORIZONTAL_SHELVES = new BooleanSetting("revanced_hide_horizontal_shelves", TRUE); public static final BooleanSetting HIDE_CAPTIONS_BUTTON = new BooleanSetting("revanced_hide_captions_button", FALSE); public static final BooleanSetting HIDE_CAST_BUTTON = new BooleanSetting("revanced_hide_cast_button", TRUE, true); public static final BooleanSetting HIDE_CHANNEL_BAR = new BooleanSetting("revanced_hide_channel_bar", FALSE);