fix(YouTube - Hide Shorts components): Hide shorts header (#455)

Co-authored-by: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
johnconner122 2023-08-23 08:35:00 +05:00 committed by GitHub
parent 7510c0632f
commit 13afac906a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,45 +12,21 @@ import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar;
import app.revanced.integrations.settings.SettingsEnum; import app.revanced.integrations.settings.SettingsEnum;
public final class ShortsFilter extends Filter { public final class ShortsFilter extends Filter {
private static final String REEL_CHANNEL_BAR_PATH = "reel_channel_bar"; private static final String REEL_CHANNEL_BAR_PATH = "reel_channel_bar.eml";
public static PivotBar pivotBar; // Set by patch. public static PivotBar pivotBar; // Set by patch.
private final StringFilterGroup channelBar; private final StringFilterGroup channelBar;
private final StringFilterGroup soundButton; private final StringFilterGroup soundButton;
private final StringFilterGroup infoPanel; private final StringFilterGroup infoPanel;
private final StringFilterGroup shortsShelfHeader;
public ShortsFilter() { public ShortsFilter() {
channelBar = new StringFilterGroup( // Home / subscription feed components.
SettingsEnum.HIDE_SHORTS_CHANNEL_BAR, var thanksButton = new StringFilterGroup(
REEL_CHANNEL_BAR_PATH
);
soundButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_SOUND_BUTTON,
"reel_pivot_button"
);
infoPanel = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_INFO_PANEL,
"shorts_info_panel_overview"
);
final var thanksButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_THANKS_BUTTON, SettingsEnum.HIDE_SHORTS_THANKS_BUTTON,
"suggested_action" "suggested_action"
); );
var shorts = new StringFilterGroup(
final var subscribeButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_SUBSCRIBE_BUTTON,
"subscribe_button"
);
final var joinButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);
final var shorts = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS, SettingsEnum.HIDE_SHORTS,
"shorts_shelf", "shorts_shelf",
"inline_shorts", "inline_shorts",
@ -58,22 +34,58 @@ public final class ShortsFilter extends Filter {
"shorts_video_cell", "shorts_video_cell",
"shorts_pivot_item" "shorts_pivot_item"
); );
// Use a different filter group for this pattern, as it requires an additional check after matching.
shortsShelfHeader = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS,
"shelf_header.eml"
);
identifierFilterGroups.addAll(shorts, shortsShelfHeader, thanksButton);
// Shorts player components.
var joinButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_JOIN_BUTTON,
"sponsor_button"
);
var subscribeButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_SUBSCRIBE_BUTTON,
"subscribe_button"
);
channelBar = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_CHANNEL_BAR,
REEL_CHANNEL_BAR_PATH
);
soundButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_SOUND_BUTTON,
"reel_pivot_button"
);
infoPanel = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_INFO_PANEL,
"shorts_info_panel_overview"
);
pathFilterGroupList.addAll(joinButton, subscribeButton, channelBar, soundButton, infoPanel); pathFilterGroupList.addAll(joinButton, subscribeButton, channelBar, soundButton, infoPanel);
identifierFilterGroupList.addAll(shorts, thanksButton);
} }
@Override @Override
boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray, boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray,
FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) { FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) {
if (matchedGroup == soundButton || matchedGroup == infoPanel || matchedGroup == channelBar) return true; if (matchedList == pathFilterGroupList) {
// Always filter if matched.
if (matchedGroup == soundButton || matchedGroup == infoPanel || matchedGroup == channelBar)
return super.isFiltered(path, identifier, protobufBufferArray, matchedList, matchedGroup, matchedIndex);
// Filter the path only when reelChannelBar is visible. // Filter other path groups from pathFilterGroupList, only when reelChannelBar is visible
if (pathFilterGroupList == matchedList) { // to avoid false positives.
return path.contains(REEL_CHANNEL_BAR_PATH); if (!path.startsWith(REEL_CHANNEL_BAR_PATH))
return false;
} else if (matchedGroup == shortsShelfHeader) {
// Because the header is used in watch history and possibly other places, check for the index,
// which is 0 when the shelf header is used for Shorts.
if (matchedIndex != 0) return false;
} }
return identifierFilterGroupList == matchedList; // Super class handles logging.
return super.isFiltered(path, identifier, protobufBufferArray, matchedList, matchedGroup, matchedIndex);
} }
public static void hideShortsShelf(final View shortsShelfView) { public static void hideShortsShelf(final View shortsShelfView) {