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

Commit

Permalink
fix(YouTube - Navigation bar components): Library button is not hidde…
Browse files Browse the repository at this point in the history
…n when `Cairo navigation bar` is applied (A/B tests)
  • Loading branch information
inotia00 authored and anddea committed Sep 16, 2024
1 parent dc5b34a commit 2017cb3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ private static ThumbnailOption optionSettingForCurrentNavigation() {
// Unknown tab, treat as the home tab;
return homeOption;
}
if (selectedNavButton.isHomeTab()) {
if (selectedNavButton == NavigationButton.HOME) {
return homeOption;
}
if (selectedNavButton.isSubscriptionsTab() || selectedNavButton.isNotificationTab()) {
if (selectedNavButton == NavigationButton.SUBSCRIPTIONS || selectedNavButton == NavigationButton.NOTIFICATIONS) {
return subscriptionsOption;
}
// A library tab variant is active.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,10 +560,10 @@ private boolean hideKeywordSettingIsActive() {
if (selectedNavButton == null) {
return hideHome; // Unknown tab, treat the same as home.
}
if (selectedNavButton.isHomeTab()) {
if (selectedNavButton == NavigationButton.HOME) {
return hideHome;
}
if (selectedNavButton.isSubscriptionsTab()) {
if (selectedNavButton == NavigationButton.SUBSCRIPTIONS) {
return hideSubscriptions;
}
// User is in the Library or Notifications tab.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,21 +251,11 @@ public static boolean hideSnackBar() {
private static final Map<NavigationButton, Boolean> shouldHideMap = new EnumMap<>(NavigationButton.class) {
{
put(NavigationButton.HOME, Settings.HIDE_NAVIGATION_HOME_BUTTON.get());
put(NavigationButton.HOME_CAIRO, Settings.HIDE_NAVIGATION_HOME_BUTTON.get());
put(NavigationButton.SHORTS, Settings.HIDE_NAVIGATION_SHORTS_BUTTON.get());
put(NavigationButton.SHORTS_CAIRO, Settings.HIDE_NAVIGATION_SHORTS_BUTTON.get());
put(NavigationButton.SUBSCRIPTIONS, Settings.HIDE_NAVIGATION_SUBSCRIPTIONS_BUTTON.get());
put(NavigationButton.SUBSCRIPTIONS_CAIRO, Settings.HIDE_NAVIGATION_SUBSCRIPTIONS_BUTTON.get());
put(NavigationButton.CREATE, Settings.HIDE_NAVIGATION_CREATE_BUTTON.get());
put(NavigationButton.CREATE_CAIRO, Settings.HIDE_NAVIGATION_CREATE_BUTTON.get());
put(NavigationButton.NOTIFICATIONS, Settings.HIDE_NAVIGATION_NOTIFICATIONS_BUTTON.get());
put(NavigationButton.NOTIFICATIONS_CAIRO, Settings.HIDE_NAVIGATION_NOTIFICATIONS_BUTTON.get());

put(NavigationButton.LIBRARY_LOGGED_OUT, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
put(NavigationButton.LIBRARY_INCOGNITO, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
put(NavigationButton.LIBRARY_OLD_UI, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
put(NavigationButton.LIBRARY_PIVOT_UNKNOWN, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
put(NavigationButton.LIBRARY_YOU, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
put(NavigationButton.LIBRARY, Settings.HIDE_NAVIGATION_LIBRARY_BUTTON.get());
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import androidx.annotation.Nullable;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.CountDownLatch;
Expand All @@ -16,15 +18,9 @@
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.settings.Settings;

/**
* @noinspection ALL
*/
@SuppressWarnings("unused")
public final class NavigationBar {

//
// Navigation bar buttons
//

/**
* How long to wait for the set nav button latch to be released. Maximum wait time must
* be as small as possible while still allowing enough time for the nav bar to update.
Expand Down Expand Up @@ -133,11 +129,11 @@ public static void navigationTabLoaded(final View navigationButtonGroup) {
try {
String lastEnumName = lastYTNavigationEnumName;

for (NavigationButton button : NavigationButton.values()) {
if (button.ytEnumName.equals(lastEnumName)) {
for (NavigationButton buttonType : NavigationButton.values()) {
if (buttonType.ytEnumNames.contains(lastEnumName)) {
Logger.printDebug(() -> "navigationTabLoaded: " + lastEnumName);
viewToButtonMap.put(navigationButtonGroup, button);
navigationTabCreatedCallback(button, navigationButtonGroup);
viewToButtonMap.put(navigationButtonGroup, buttonType);
navigationTabCreatedCallback(buttonType, navigationButtonGroup);
return;
}
}
Expand All @@ -161,10 +157,10 @@ public static void navigationTabLoaded(final View navigationButtonGroup) {
public static void navigationImageResourceTabLoaded(View view) {
// 'You' tab has no YT enum name and the enum hook is not called for it.
// Compare the last enum to figure out which tab this actually is.
if (CREATE.ytEnumName.equals(lastYTNavigationEnumName)) {
if (CREATE.ytEnumNames.contains(lastYTNavigationEnumName)) {
navigationTabLoaded(view);
} else {
lastYTNavigationEnumName = NavigationButton.LIBRARY_YOU.ytEnumName;
lastYTNavigationEnumName = NavigationButton.LIBRARY.ytEnumNames.get(0);
navigationTabLoaded(view);
}
}
Expand Down Expand Up @@ -237,49 +233,39 @@ private static void navigationTabCreatedCallback(NavigationButton button, View t
}

public enum NavigationButton {
HOME("PIVOT_HOME"),
HOME_CAIRO("TAB_HOME_CAIRO"),
SHORTS("TAB_SHORTS"),
SHORTS_CAIRO("TAB_SHORTS_CAIRO"),
HOME("PIVOT_HOME", "TAB_HOME_CAIRO"),
SHORTS("TAB_SHORTS", "TAB_SHORTS_CAIRO"),
/**
* Create new video tab.
* This tab will never be in a selected state, even if the create video UI is on screen.
*/
CREATE("CREATION_TAB_LARGE"),
CREATE_CAIRO("CREATION_TAB_LARGE_CAIRO"),
SUBSCRIPTIONS("PIVOT_SUBSCRIPTIONS"),
SUBSCRIPTIONS_CAIRO("TAB_SUBSCRIPTIONS_CAIRO"),
CREATE("CREATION_TAB_LARGE", "CREATION_TAB_LARGE_CAIRO"),
SUBSCRIPTIONS("PIVOT_SUBSCRIPTIONS", "TAB_SUBSCRIPTIONS_CAIRO"),
/**
* Notifications tab. Only present when
* {@link Settings#SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON} is active.
*/
NOTIFICATIONS("TAB_ACTIVITY"),
NOTIFICATIONS_CAIRO("TAB_ACTIVITY_CAIRO"),
/**
* Library tab when the user is not logged in.
*/
LIBRARY_LOGGED_OUT("ACCOUNT_CIRCLE"),
NOTIFICATIONS("TAB_ACTIVITY", "TAB_ACTIVITY_CAIRO"),
/**
* User is logged in with incognito mode enabled.
* Library tab, including if the user is in incognito mode or when logged out.
*/
LIBRARY_INCOGNITO("INCOGNITO_CIRCLE"),
/**
* Old library tab (pre 'You' layout), only present when version spoofing.
*/
LIBRARY_OLD_UI("VIDEO_LIBRARY_WHITE"),
/**
* 'You' library tab that is sometimes momentarily loaded.
* When this is loaded, {@link #LIBRARY_YOU} is also present.
* <p>
* This might be a temporary tab while the user profile photo is loading,
* but its exact purpose is not entirely clear.
*/
LIBRARY_PIVOT_UNKNOWN("PIVOT_LIBRARY"),
/**
* Modern library tab with 'You' layout.
*/
// The hooked YT code does not use an enum, and a dummy name is used here.
LIBRARY_YOU("YOU_LIBRARY_DUMMY_PLACEHOLDER_NAME");
LIBRARY(
// Modern library tab with 'You' layout.
// The hooked YT code does not use an enum, and a dummy name is used here.
"YOU_LIBRARY_DUMMY_PLACEHOLDER_NAME",
// User is logged out.
"ACCOUNT_CIRCLE",
"ACCOUNT_CIRCLE_CAIRO",
// User is logged in with incognito mode enabled.
"INCOGNITO_CIRCLE",
"INCOGNITO_CAIRO",
// Old library tab (pre 'You' layout), only present when version spoofing.
"VIDEO_LIBRARY_WHITE",
// 'You' library tab that is sometimes momentarily loaded.
// This might be a temporary tab while the user profile photo is loading,
// but its exact purpose is not entirely clear.
"PIVOT_LIBRARY"
);

@Nullable
private static volatile NavigationButton selectedNavigationButton;
Expand All @@ -290,14 +276,14 @@ public enum NavigationButton {
* or YT abruptly changes the navigation layout for some other reason.
* <p>
* All code calling this method should handle a null return value.
*
* <p>
* <b>Due to issues with how YT processes physical back button events,
* this patch uses workarounds that can cause this method to take up to 75ms
* if the device back button was recently pressed.</b>
*
* @return The active navigation tab.
* If the user is in the upload video UI, this returns tab that is still visually
* selected on screen (whatever tab the user was on before tapping the upload button).
* If the user is in the upload video UI, this returns tab that is still visually
* selected on screen (whatever tab the user was on before tapping the upload button).
*/
@Nullable
public static NavigationButton getSelectedNavigationButton() {
Expand All @@ -308,32 +294,10 @@ public static NavigationButton getSelectedNavigationButton() {
/**
* YouTube enum name for this tab.
*/
private final String ytEnumName;

NavigationButton(String ytEnumName) {
this.ytEnumName = ytEnumName;
}

public boolean isHomeTab() {
return this == HOME || this == HOME_CAIRO;
}

public boolean isShortsTab() {
return this == SHORTS || this == SHORTS_CAIRO;
}

public boolean isSubscriptionsTab() {
return this == SUBSCRIPTIONS || this == SUBSCRIPTIONS_CAIRO;
}

public boolean isNotificationTab() {
return this == NOTIFICATIONS || this == NOTIFICATIONS_CAIRO;
}
private final List<String> ytEnumNames;

public boolean isLibraryOrYouTab() {
return this == LIBRARY_YOU || this == LIBRARY_PIVOT_UNKNOWN
|| this == LIBRARY_OLD_UI || this == LIBRARY_INCOGNITO
|| this == LIBRARY_LOGGED_OUT;
NavigationButton(String... ytEnumNames) {
this.ytEnumNames = Arrays.asList(ytEnumNames);
}
}
}

0 comments on commit 2017cb3

Please sign in to comment.