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

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Mar 26, 2024
1 parent 0a745e7 commit 58bebfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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<NavigationBar.NavigationButton, Boolean> 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();

Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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.
Expand Down Expand Up @@ -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"),
/**
Expand Down

0 comments on commit 58bebfb

Please sign in to comment.