Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Hide feed components): Sometimes Hide carousel shelf
Browse files Browse the repository at this point in the history
…setting doesn't work
  • Loading branch information
inotia00 authored and anddea committed Jul 31, 2024
1 parent f291c2c commit c7476ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package app.revanced.integrations.youtube.patches.components;

import static app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton;

import androidx.annotation.Nullable;

import app.revanced.integrations.shared.patches.components.ByteArrayFilterGroup;
Expand All @@ -11,6 +9,7 @@
import app.revanced.integrations.shared.utils.Logger;
import app.revanced.integrations.shared.utils.StringTrieSearch;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar;
import app.revanced.integrations.youtube.shared.RootView;

@SuppressWarnings("unused")
Expand All @@ -35,6 +34,7 @@ public final class FeedComponentsFilter extends Filter {
public final StringFilterGroup carouselShelf;
private final StringFilterGroup channelProfile;
private final StringFilterGroup communityPosts;
private final StringFilterGroup libraryShelf;
private final ByteArrayFilterGroup visitStoreButton;

private static final StringTrieSearch communityPostsFeedGroupSearch = new StringTrieSearch();
Expand Down Expand Up @@ -78,11 +78,17 @@ public FeedComponentsFilter() {
"search_bar_entry_point"
);

libraryShelf = new StringFilterGroup(
null,
"library_recent_shelf.eml"
);

addIdentifierCallbacks(
carouselShelf,
chipsShelf,
communityPosts,
feedSearchBar
feedSearchBar,
libraryShelf
);

// Paths.
Expand Down Expand Up @@ -224,8 +230,8 @@ private static boolean hideShelves() {
return true;
}

NavigationButton selectedNavButton = NavigationButton.getSelectedNavigationButton();
if (selectedNavButton != null && !selectedNavButton.isLibraryOrYouTab()) {
// Check NavigationBar index. If not in Library tab, then filter.
if (NavigationBar.isNotLibraryTab()) {
return true;
}

Expand All @@ -240,7 +246,20 @@ private static boolean hideShelves() {
@Override
public boolean isFiltered(String path, @Nullable String identifier, String allValue, byte[] protobufBufferArray,
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
if (matchedGroup == carouselShelf) {
if (matchedGroup == libraryShelf) {
// The library shelf is hidden in the following situations:
//
// 1. Click on the Library tab.
// 2. Click on the Home tab.
// 3. Press the back button on the Home tab. The Library tab, which was the last tab opened, opens.
// 4. The library shelf (playlists) is hidden.
//
// As a temporary workaround, use the navigation bar index.
//
// If {@link libraryShelf}, a component of the Library tab, is detected, change the navigation bar index to 3
NavigationBar.setNavigationTabIndex(3);
return false;
} else if (matchedGroup == carouselShelf) {
if (hideShelves()) {
return super.isFiltered(path, identifier, allValue, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,36 @@ public static void navigationImageResourceTabLoaded(View view) {
}
}

private static int lastIndex = 0;

/**
* Injection point.
*/
public static void setNavigationTabIndex(int index) {
if (lastIndex == index) {
return;
}

lastIndex = index;
Logger.printDebug(() -> "Changed navigation index to : " + index);
}

public static boolean isNotLibraryTab() {
return lastIndex < 3;
}

/**
* Injection point.
*/
public static void navigationTabSelected(View navButtonImageView, boolean isSelected) {
public static void navigationTabSelected(View navButtonImageView, int index, boolean isSelected) {
try {
if (!isSelected) {
if (!isSelected || lastIndex == index) {
return;
}

lastIndex = index;
Logger.printDebug(() -> "Changed navigation index to : " + index);

NavigationButton button = viewToButtonMap.get(navButtonImageView);

if (button == null) { // An unknown tab was selected.
Expand Down

0 comments on commit c7476ec

Please sign in to comment.