merge to layouts components patch

This commit is contained in:
oSumAtrIX 2024-04-06 20:33:28 +02:00
parent 0c3a3400bc
commit 115c963112
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 26 additions and 44 deletions

View File

@ -1,42 +0,0 @@
package app.revanced.integrations.youtube.patches.components;
import androidx.annotation.Nullable;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar;
import app.revanced.integrations.youtube.shared.PlayerType;
@SuppressWarnings("unused")
public final class HorizontalShelvesFilter extends Filter {
public HorizontalShelvesFilter() {
addPathCallbacks(
new StringFilterGroup(
Settings.HIDE_HORIZONTAL_SHELVES,
"horizontal_video_shelf.eml",
"horizontal_shelf.eml"
)
);
}
@Override
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
if (contentIndex == 0 && shouldHideShelves()) {
return super.isFiltered(path, identifier, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
return false;
}
private static boolean shouldHideShelves() {
// 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();
}
}

View File

@ -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();
}
}