diff --git a/app/src/main/java/app/revanced/integrations/patches/components/SuggestionsShelfFilter.java b/app/src/main/java/app/revanced/integrations/patches/components/SuggestionsShelfFilter.java index ebfc93ef49..53b3e1e687 100644 --- a/app/src/main/java/app/revanced/integrations/patches/components/SuggestionsShelfFilter.java +++ b/app/src/main/java/app/revanced/integrations/patches/components/SuggestionsShelfFilter.java @@ -18,6 +18,10 @@ public class SuggestionsShelfFilter extends Filter { SettingsEnum.SPOOF_APP_VERSION.getBoolean() && SettingsEnum.SPOOF_APP_VERSION_TARGET.getString().compareTo("17.08.35") <= 0; + // Must be volatile or synchronized, as litho filtering runs off main thread and this field is then access from the main thread. + public static volatile boolean isLibraryRecentShelfVisible; + public static volatile boolean isHomeFeedVisible; + public SuggestionsShelfFilter() { pathFilterGroupList.addAll( new StringFilterGroup( @@ -31,11 +35,15 @@ public SuggestionsShelfFilter() { boolean isFiltered(@Nullable String identifier, String path, byte[] protobufBufferArray, FilterGroupList matchedList, FilterGroup matchedGroup, int matchedIndex) { // Only one filter is added, so the matched group must be the horizontal video shelf. - if (path.contains("library_recent_shelf")) + if (path.contains("library_recent_shelf")) { // If the library shelf is detected, set the current navbar index to 4 NavBarIndexHook.setCurrentNavBarIndex(4); - - else if (NavBarIndexHook.isNotLibraryTab()) + isLibraryRecentShelfVisible = true; + } else if (path.contains("more_drawer")) { + // If drawer button is detected, set the current NavBar index to zero + NavBarIndexHook.setCurrentNavBarIndex(0); + isHomeFeedVisible = true; + } else if (NavBarIndexHook.isNotLibraryTab()) // When the Library Tab is not detected, hide the suggestion shelf return super.isFiltered(path, identifier, protobufBufferArray, matchedList, matchedGroup, matchedIndex); @@ -44,7 +52,7 @@ else if (NavBarIndexHook.isNotLibraryTab()) /** * Injection point. - * + *

* Only used to hide breaking news on tablet layout which still uses the old UI components. */ public static void hideBreakingNews(View view) { diff --git a/app/src/main/java/app/revanced/integrations/utils/NavBarIndexHook.java b/app/src/main/java/app/revanced/integrations/utils/NavBarIndexHook.java index ff141637d3..b047ae0915 100644 --- a/app/src/main/java/app/revanced/integrations/utils/NavBarIndexHook.java +++ b/app/src/main/java/app/revanced/integrations/utils/NavBarIndexHook.java @@ -2,6 +2,8 @@ import android.content.Context; +import app.revanced.integrations.patches.components.SuggestionsShelfFilter; + public class NavBarIndexHook { private static int currentNavBarIndex = 0; @@ -20,6 +22,16 @@ public static void setCurrentNavBarIndex(int navBarIndex) { } public static void setLastNavBarIndex() { + // if we come to back to Library fragment from any other like downloads page, playlists, your videos, or your clips + // NavBar index should still be same + if (SuggestionsShelfFilter.isLibraryRecentShelfVisible && currentNavBarIndex == 4) + return; + + // if we come to back to Home fragment from any other like trending, or news, or sports page + // NavBar index should still be same + if (SuggestionsShelfFilter.isHomeFeedVisible && currentNavBarIndex == 0) + return; + currentNavBarIndex = lastNavBarIndex; }