Skip to content

Commit

Permalink
fix(YouTube - Shorts components): Hide Shorts shelves setting somet…
Browse files Browse the repository at this point in the history
…imes hides shelves in the library tab
  • Loading branch information
anddea committed Oct 29, 2024
1 parent 4be6d9e commit 4ad3857
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.shared.utils.StringTrieSearch;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton;
import app.revanced.integrations.youtube.shared.RootView;

@SuppressWarnings("unused")
Expand All @@ -26,21 +27,13 @@ public final class ShortsShelfFilter extends Filter {
private static final StringTrieSearch feedGroup = new StringTrieSearch();
private static final BooleanSetting hideShortsShelf = Settings.HIDE_SHORTS_SHELF;
private static final BooleanSetting hideChannel = Settings.HIDE_SHORTS_SHELF_CHANNEL;
private static final boolean hideHomeAndRelatedVideos = Settings.HIDE_SHORTS_SHELF_HOME_RELATED_VIDEOS.get();
private static final boolean hideSubscriptions = Settings.HIDE_SHORTS_SHELF_SUBSCRIPTIONS.get();
private static final boolean hideSearch = Settings.HIDE_SHORTS_SHELF_SEARCH.get();
private static final boolean hideHistory = Settings.HIDE_SHORTS_SHELF_HISTORY.get();
private final StringTrieSearch exceptions = new StringTrieSearch();
private static final ByteArrayFilterGroup channelProfileShelfHeader =
new ByteArrayFilterGroup(
hideChannel,
"Shorts"
);

public ShortsShelfFilter() {
if (!hideHistory) {
exceptions.addPattern("library_recent_shelf.eml");
}
feedGroup.addPattern(CONVERSATION_CONTEXT_FEED_IDENTIFIER);

final StringFilterGroup channelProfile = new StringFilterGroup(
Expand Down Expand Up @@ -94,9 +87,6 @@ public ShortsShelfFilter() {
@Override
public boolean isFiltered(String path, @Nullable String identifier, String allValue, byte[] protobufBufferArray,
StringFilterGroup matchedGroup, FilterContentType contentType, int contentIndex) {
if (exceptions.matches(path)) {
return false;
}
// Check channel profile components first
if (matchedGroup == shelfHeaderPath) {
// Because the header is used in watch history and possibly other places, check for the index,
Expand All @@ -113,7 +103,7 @@ public boolean isFiltered(String path, @Nullable String identifier, String allVa
return super.isFiltered(path, identifier, allValue, protobufBufferArray, matchedGroup, contentType, contentIndex);
}
// Check feed components
if (!hideShelves()) {
if (!shouldHideShortsFeedItems(NavigationButton.getSelectedNavigationButton(), RootView.getBrowseId())) {
return false;
}
if (matchedGroup == compactFeedVideoPath) {
Expand All @@ -133,7 +123,12 @@ public boolean isFiltered(String path, @Nullable String identifier, String allVa
return super.isFiltered(path, identifier, allValue, protobufBufferArray, matchedGroup, contentType, contentIndex);
}

private static boolean hideShelves() {
private static boolean shouldHideShortsFeedItems(NavigationButton selectedNavButton, String browseId) {
final boolean hideHomeAndRelatedVideos = Settings.HIDE_SHORTS_SHELF_HOME_RELATED_VIDEOS.get();
final boolean hideSubscriptions = Settings.HIDE_SHORTS_SHELF_SUBSCRIPTIONS.get();
final boolean hideSearch = Settings.HIDE_SHORTS_SHELF_SEARCH.get();
final boolean hideHistory = Settings.HIDE_SHORTS_SHELF_HISTORY.get();

if (hideHomeAndRelatedVideos && hideSubscriptions && hideSearch && hideHistory) {
// Shorts suggestions can load in the background if a video is opened and
// then immediately minimized before any suggestions are loaded.
Expand All @@ -157,12 +152,10 @@ private static boolean hideShelves() {
return hideSearch;
}

// Avoid checking navigation button status if all other Shorts should show.
if (!hideHomeAndRelatedVideos && !hideSubscriptions && !hideHistory) {
return false;
// Unknown tab, treat the same as home.
if (selectedNavButton == null) {
return hideHomeAndRelatedVideos;
}

final String browseId = RootView.getBrowseId();
switch (browseId) {
case BROWSE_ID_HISTORY, BROWSE_ID_LIBRARY, BROWSE_ID_NOTIFICATION_INBOX -> {
return hideHistory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,11 @@ public class Settings extends BaseSettings {
public static final BooleanSetting DISABLE_RESUMING_SHORTS_PLAYER = new BooleanSetting("revanced_disable_resuming_shorts_player", TRUE);
public static final BooleanSetting HIDE_SHORTS_FLOATING_BUTTON = new BooleanSetting("revanced_hide_shorts_floating_button", TRUE);
public static final BooleanSetting HIDE_SHORTS_SHELF = new BooleanSetting("revanced_hide_shorts_shelf", TRUE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_CHANNEL = new BooleanSetting("revanced_hide_shorts_shelf_channel", FALSE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_HOME_RELATED_VIDEOS = new BooleanSetting("revanced_hide_shorts_shelf_home_related_videos", TRUE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_shelf_subscriptions", TRUE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_SEARCH = new BooleanSetting("revanced_hide_shorts_shelf_search", TRUE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_HISTORY = new BooleanSetting("revanced_hide_shorts_shelf_history", FALSE, true);
public static final BooleanSetting HIDE_SHORTS_SHELF_CHANNEL = new BooleanSetting("revanced_hide_shorts_shelf_channel", FALSE);
public static final BooleanSetting HIDE_SHORTS_SHELF_HOME_RELATED_VIDEOS = new BooleanSetting("revanced_hide_shorts_shelf_home_related_videos", TRUE);
public static final BooleanSetting HIDE_SHORTS_SHELF_SUBSCRIPTIONS = new BooleanSetting("revanced_hide_shorts_shelf_subscriptions", TRUE);
public static final BooleanSetting HIDE_SHORTS_SHELF_SEARCH = new BooleanSetting("revanced_hide_shorts_shelf_search", TRUE);
public static final BooleanSetting HIDE_SHORTS_SHELF_HISTORY = new BooleanSetting("revanced_hide_shorts_shelf_history", FALSE);
public static final IntegerSetting CHANGE_SHORTS_REPEAT_STATE = new IntegerSetting("revanced_change_shorts_repeat_state", 0);

// PreferenceScreen: Shorts - Shorts player components
Expand Down

0 comments on commit 4ad3857

Please sign in to comment.