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

Commit

Permalink
fix(YouTube - Navigation bar hook): Handle if search is active but hi…
Browse files Browse the repository at this point in the history
…dden behind a maximized player
  • Loading branch information
LisoUseInAIKyrios committed Apr 3, 2024
1 parent eaa2e11 commit cbccb46
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ private static Uri validateSettings() {
}

private static EnumSetting<ThumbnailOption> optionSettingForCurrentNavigation() {
if (NavigationBar.isSearchBarActive()) { // Must check search first.
return ALT_THUMBNAIL_SEARCH;
}
// Must check player type first, as search bar can be active behind the player.
if (PlayerType.getCurrent().isMaximizedOrFullscreen()) {
return ALT_THUMBNAIL_PLAYER;
}
// Must check second, as search can be from any tab.
if (NavigationBar.isSearchBarActive()) {
return ALT_THUMBNAIL_SEARCH;
}
if (NavigationButton.HOME.isSelected()) {
return ALT_THUMBNAIL_HOME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,27 @@ private static void logNavigationState(String state) {
}

private static boolean hideKeywordSettingIsActive() {
if (NavigationBar.isSearchBarActive()) {
// Must check first. Search bar can be active with almost any tab.
logNavigationState("Search");
return Settings.HIDE_KEYWORD_CONTENT_SEARCH.get();
} else if (PlayerType.getCurrent().isMaximizedOrFullscreen()) {
// Must check player type first, as search bar can be active behind the player.
if (PlayerType.getCurrent().isMaximizedOrFullscreen()) {
// For now, consider the under video results the same as the home feed.
logNavigationState("Player active");
return Settings.HIDE_KEYWORD_CONTENT_HOME.get();
} else if (NavigationButton.HOME.isSelected()) {
}
// Must check second, as search can be from any tab.
if (NavigationBar.isSearchBarActive()) {
logNavigationState("Search");
return Settings.HIDE_KEYWORD_CONTENT_SEARCH.get();
}
if (NavigationButton.HOME.isSelected()) {
logNavigationState("Home tab");
return Settings.HIDE_KEYWORD_CONTENT_HOME.get();
} else if (NavigationButton.SUBSCRIPTIONS.isSelected()) {
}
if (NavigationButton.SUBSCRIPTIONS.isSelected()) {
logNavigationState("Subscription tab");
return Settings.HIDE_SUBSCRIPTIONS_BUTTON.get();
} else {
// User is in the Library or Notifications tab.
logNavigationState("Ignored tab");
}
// User is in the Library or Notifications tab.
logNavigationState("Ignored tab");
return false;
}

Expand Down Expand Up @@ -195,6 +198,7 @@ private static boolean phrasesWillHideAllVideos(@NonNull String[] phrases) {

private synchronized void parseKeywords() { // Must be synchronized since Litho is multi-threaded.
String rawKeywords = Settings.HIDE_KEYWORD_CONTENT_PHRASES.get();
//noinspection StringEquality
if (rawKeywords == lastKeywordPhrasesParsed) {
Logger.printDebug(() -> "Using previously initialized search");
return; // Another thread won the race, and search is already initialized.
Expand Down Expand Up @@ -265,6 +269,7 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
if (!hideKeywordSettingIsActive()) return false;

// Field is intentionally compared using reference equality.
//noinspection StringEquality
if (Settings.HIDE_KEYWORD_CONTENT_PHRASES.get() != lastKeywordPhrasesParsed) {
// User changed the keywords.
parseKeywords();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,19 @@ boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBuff
}

private static boolean shouldHideShortsFeedItems() {
if (NavigationBar.isSearchBarActive()) { // Must check search first.
// Must check player type first, as search bar can be active behind the player.
if (PlayerType.getCurrent().isMaximizedOrFullscreen()) {
// For now, consider the under video results the same as the home feed.
return Settings.HIDE_SHORTS_HOME.get();
}
// Must check second, as search can be from any tab.
if (NavigationBar.isSearchBarActive()) {
return Settings.HIDE_SHORTS_SEARCH.get();
} else if (PlayerType.getCurrent().isMaximizedOrFullscreen()
|| NavigationBar.NavigationButton.HOME.isSelected()) {
}
if (NavigationBar.NavigationButton.HOME.isSelected()) {
return Settings.HIDE_SHORTS_HOME.get();
} else if (NavigationBar.NavigationButton.SUBSCRIPTIONS.isSelected()) {
}
if (NavigationBar.NavigationButton.SUBSCRIPTIONS.isSelected()) {
return Settings.HIDE_SHORTS_SUBSCRIPTIONS.get();
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public static void searchBarResultsViewLoaded(View searchbarResults) {
}

/**
* @return If the search bar is on screen.
* @return If the search bar is on screen. This includes if the player
* is on screen and the search results are behind the player (and not visible).
* Detecting the search is covered by the player can be done by checking {@link PlayerType#isMaximizedOrFullscreen()}.
*/
public static boolean isSearchBarActive() {
View searchbarResults = searchBarResultsRef.get();
return searchbarResults != null && searchbarResults.getParent() != null;
}


/**
* Last YT navigation enum loaded. Not necessarily the active navigation tab.
*/
Expand All @@ -44,7 +45,7 @@ public static boolean isSearchBarActive() {
/**
* Injection point.
*/
public static void setLastAppNavigationEnum(@Nullable Enum ytNavigationEnumName) {
public static void setLastAppNavigationEnum(@Nullable Enum<?> ytNavigationEnumName) {
if (ytNavigationEnumName != null) {
lastYTNavigationEnumName = ytNavigationEnumName.name();
}
Expand Down

0 comments on commit cbccb46

Please sign in to comment.