From 58bebfb73eec7834b33c8d3a153907c5390f7a64 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 26 Mar 2024 20:08:45 +0100 Subject: [PATCH] refactor --- .../patches/NavigationButtonsPatch.java | 34 ++++++++----------- .../youtube/shared/NavigationBar.java | 16 ++++----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/NavigationButtonsPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/NavigationButtonsPatch.java index 569d8815bd..32fac79d66 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/NavigationButtonsPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/NavigationButtonsPatch.java @@ -1,15 +1,22 @@ package app.revanced.integrations.youtube.patches; import android.view.View; - import app.revanced.integrations.youtube.settings.Settings; import app.revanced.integrations.youtube.shared.NavigationBar; +import java.util.HashMap; +import java.util.Map; + @SuppressWarnings("unused") public final class NavigationButtonsPatch { - private static final Boolean HIDE_HOME_BUTTON = Settings.HIDE_HOME_BUTTON.get(); - private static final Boolean HIDE_CREATE_BUTTON = Settings.HIDE_CREATE_BUTTON.get(); - private static final Boolean HIDE_SHORTS_BUTTON = Settings.HIDE_SHORTS_BUTTON.get(); + private static final Map shouldHideMap = new HashMap<>() { + { + put(NavigationBar.NavigationButton.HOME, Settings.HIDE_HOME_BUTTON.get()); + put(NavigationBar.NavigationButton.CREATE, Settings.HIDE_CREATE_BUTTON.get()); + put(NavigationBar.NavigationButton.SHORTS, Settings.HIDE_SHORTS_BUTTON.get()); + } + }; + private static final Boolean SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = Settings.SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON.get(); @@ -20,22 +27,11 @@ public static boolean switchCreateWithNotificationButton() { return SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON; } + /** + * Injection point. + */ public static void navigationTabCreated(NavigationBar.NavigationButton button, View tabView) { - final boolean shouldHide; - switch (button) { - case HOME: - shouldHide = HIDE_HOME_BUTTON; - break; - case SHORTS: - shouldHide = HIDE_SHORTS_BUTTON; - break; - case CREATE: - shouldHide = HIDE_CREATE_BUTTON; - break; - default: - return; - } - if (shouldHide) { + if (Boolean.TRUE.equals(shouldHideMap.get(button))) { tabView.setVisibility(View.GONE); } } diff --git a/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java b/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java index 6ae5e735b6..374b7df3f4 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java +++ b/app/src/main/java/app/revanced/integrations/youtube/shared/NavigationBar.java @@ -1,19 +1,17 @@ package app.revanced.integrations.youtube.shared; -import static app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton.CREATE; - import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; - import androidx.annotation.Nullable; - -import java.lang.ref.WeakReference; - import app.revanced.integrations.shared.Logger; import app.revanced.integrations.shared.Utils; import app.revanced.integrations.youtube.settings.Settings; +import java.lang.ref.WeakReference; + +import static app.revanced.integrations.youtube.shared.NavigationBar.NavigationButton.CREATE; + @SuppressWarnings("unused") public final class NavigationBar { private static volatile boolean searchbarIsActive; @@ -70,7 +68,7 @@ public static void navigationTabLoaded(final View navigationButtonGroup) { } } // Log the unknown tab as exception level, only if debug is enabled. - // This is because unknown tabs do no harm and it's only relevant to developers. + // This is because unknown tabs do no harm, and it's only relevant to developers. if (Settings.DEBUG.get()) { Logger.printException(() -> "Unknown tab: " + lastEnumName + " view: " + navigationButtonGroup.getClass()); @@ -83,7 +81,7 @@ public static void navigationTabLoaded(final View navigationButtonGroup) { /** * Injection point. * - * Unique hook just for the create and 'You' tab. + * Unique hook just for the 'Create' and 'You' tab. */ public static void navigationImageResourceTabLoaded(View view) { // 'You' tab has no YT enum name and the enum hook is not called for it. @@ -133,7 +131,7 @@ public enum NavigationButton { * When this is loaded, {@link #LIBRARY_YOU} is also present. * * This might be a temporary tab while the user profile photo is loading, - * but it's exact purpose is not entirely clear. + * but its exact purpose is not entirely clear. */ LIBRARY_PIVOT_UNKNOWN("PIVOT_LIBRARY"), /**