feat(YouTube - Navigation bar components): Separate Enable translucent navigation bar setting into Disable light translucent bar and Disable dark translucent bar settings

This commit is contained in:
inotia00
2024-12-21 13:30:25 +09:00
parent e3128a9552
commit b5f9a951d3
8 changed files with 87 additions and 20 deletions

View File

@ -462,6 +462,16 @@ public class Utils {
return false;
}
public static boolean isDarkModeEnabled() {
return isDarkModeEnabled(context);
}
public static boolean isDarkModeEnabled(Context context) {
Configuration config = context.getResources().getConfiguration();
final int currentNightMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
return currentNightMode == Configuration.UI_MODE_NIGHT_YES;
}
/**
* @return whether the device's API level is higher than a specific SDK version.
*/

View File

@ -5,6 +5,7 @@ import static app.revanced.extension.shared.utils.Utils.getChildView;
import static app.revanced.extension.shared.utils.Utils.hideViewByLayoutParams;
import static app.revanced.extension.shared.utils.Utils.hideViewGroupByMarginLayoutParams;
import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;
import static app.revanced.extension.shared.utils.Utils.isSDKAbove;
import static app.revanced.extension.youtube.patches.utils.PatchStatus.ImageSearchButton;
import static app.revanced.extension.youtube.shared.NavigationBar.NavigationButton;
@ -214,10 +215,6 @@ public class GeneralPatch {
return Settings.ENABLE_NARROW_NAVIGATION_BUTTONS.get() || original;
}
public static boolean enableTranslucentNavigationBar() {
return Settings.ENABLE_TRANSLUCENT_NAVIGATION_BAR.get();
}
/**
* @noinspection ALL
*/
@ -248,6 +245,31 @@ public class GeneralPatch {
hideViewUnderCondition(Settings.HIDE_NAVIGATION_BAR.get(), view);
}
private static final Boolean DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT
= Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT.get();
private static final Boolean DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK
= Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK.get();
public static boolean useTranslucentNavigationButtons(boolean original) {
// Feature requires Android 13+
if (!isSDKAbove(33)) {
return original;
}
if (!DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK && !DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT) {
return original;
}
if (DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK && DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT) {
return false;
}
return Utils.isDarkModeEnabled()
? !DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK
: !DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT;
}
// endregion
// region [Remove viewer discretion dialog] patch

View File

@ -189,7 +189,8 @@ public class Settings extends BaseSettings {
public static final BooleanSetting HIDE_NAVIGATION_SUBSCRIPTIONS_BUTTON = new BooleanSetting("revanced_hide_navigation_subscriptions_button", FALSE, true);
public static final BooleanSetting HIDE_NAVIGATION_LABEL = new BooleanSetting("revanced_hide_navigation_label", FALSE, true);
public static final BooleanSetting SWITCH_CREATE_WITH_NOTIFICATIONS_BUTTON = new BooleanSetting("revanced_switch_create_with_notifications_button", TRUE, true, "revanced_switch_create_with_notifications_button_user_dialog_message");
public static final BooleanSetting ENABLE_TRANSLUCENT_NAVIGATION_BAR = new BooleanSetting("revanced_enable_translucent_navigation_bar", FALSE, true);
public static final BooleanSetting DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT = new BooleanSetting("revanced_disable_translucent_navigation_bar_light", FALSE, true);
public static final BooleanSetting DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK = new BooleanSetting("revanced_disable_translucent_navigation_bar_dark", FALSE, true);
public static final BooleanSetting HIDE_NAVIGATION_BAR = new BooleanSetting("revanced_hide_navigation_bar", FALSE, true);
// PreferenceScreen: General - Override buttons

View File

@ -204,8 +204,9 @@ public class ReVancedSettingsPreference extends ReVancedPreferenceFragment {
Settings.REPLACE_TOOLBAR_CREATE_BUTTON_TYPE
);
enableDisablePreferences(
!isSDKAbove(31),
Settings.ENABLE_TRANSLUCENT_NAVIGATION_BAR
!isSDKAbove(33),
Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_LIGHT,
Settings.DISABLE_TRANSLUCENT_NAVIGATION_BAR_DARK
);
}

View File

@ -74,7 +74,23 @@ internal val setEnumMapFingerprint = legacyFingerprint(
literals = listOf(ytFillBell),
)
internal val translucentNavigationBarFingerprint = legacyFingerprint(
name = "translucentNavigationBarFingerprint",
literals = listOf(45630927L),
internal const val TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG = 45630927L
internal val translucentNavigationButtonsFeatureFlagFingerprint = legacyFingerprint(
name = "translucentNavigationButtonsFeatureFlagFingerprint",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "V",
literals = listOf(TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG)
)
/**
* The device on screen back/home/recent buttons.
*/
internal const val TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG = 45632194L
internal val translucentNavigationButtonsSystemFeatureFlagFingerprint = legacyFingerprint(
name = "translucentNavigationButtonsSystemFeatureFlagFingerprint",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
returnType = "Z",
literals = listOf(TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG)
)

View File

@ -11,7 +11,7 @@ import app.revanced.patches.youtube.utils.navigation.addBottomBarContainerHook
import app.revanced.patches.youtube.utils.navigation.hookNavigationButtonCreated
import app.revanced.patches.youtube.utils.navigation.navigationBarHookPatch
import app.revanced.patches.youtube.utils.patch.PatchList.NAVIGATION_BAR_COMPONENTS
import app.revanced.patches.youtube.utils.playservice.is_19_23_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_25_or_greater
import app.revanced.patches.youtube.utils.playservice.is_19_28_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.resourceid.sharedResourceIdPatch
@ -84,11 +84,24 @@ val navigationBarComponentsPatch = bytecodePatch(
// region patch for enable translucent navigation bar
if (is_19_23_or_greater) {
translucentNavigationBarFingerprint.injectLiteralInstructionBooleanCall(
45630927L,
"$GENERAL_CLASS_DESCRIPTOR->enableTranslucentNavigationBar()Z"
)
if (is_19_25_or_greater) {
arrayOf(
Triple(
translucentNavigationButtonsFeatureFlagFingerprint,
TRANSLUCENT_NAVIGATION_BUTTONS_FEATURE_FLAG,
"useTranslucentNavigationButtons"
),
Triple(
translucentNavigationButtonsSystemFeatureFlagFingerprint,
TRANSLUCENT_NAVIGATION_BUTTONS_SYSTEM_FEATURE_FLAG,
"useTranslucentNavigationButtons"
)
).forEach {
it.first.injectLiteralInstructionBooleanCall(
it.second,
"$GENERAL_CLASS_DESCRIPTOR->${it.third}(Z)Z"
)
}
settingArray += "SETTINGS: TRANSLUCENT_NAVIGATION_BAR"
}

View File

@ -537,9 +537,12 @@ Also, ads will no longer be blocked in Shorts.
If this setting do not take effect, try switching to Incognito mode."</string>
<string name="revanced_enable_translucent_navigation_bar_title">Enable translucent navigation bar</string>
<string name="revanced_enable_translucent_navigation_bar_summary_on">Navigation bar is translucent.</string>
<string name="revanced_enable_translucent_navigation_bar_summary_off">Navigation bar is opaque.</string>
<string name="revanced_disable_translucent_navigation_bar_light_title">Disable light translucent bar</string>
<string name="revanced_disable_translucent_navigation_bar_light_summary_on">Light mode navigation bar is opaque.</string>
<string name="revanced_disable_translucent_navigation_bar_light_summary_off">Light mode navigation bar is opaque or translucent.</string>
<string name="revanced_disable_translucent_navigation_bar_dark_title">Disable dark translucent bar</string>
<string name="revanced_disable_translucent_navigation_bar_dark_summary_on">Dark mode navigation bar is opaque.</string>
<string name="revanced_disable_translucent_navigation_bar_dark_summary_off">Dark mode navigation bar is opaque or translucent.</string>
<string name="revanced_hide_navigation_bar_title">Hide navigation bar</string>
<string name="revanced_hide_navigation_bar_summary_on">Navigation bar is hidden.</string>
<string name="revanced_hide_navigation_bar_summary_off">Navigation bar is shown.</string>

View File

@ -214,7 +214,8 @@
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>SETTINGS: HIDE_NAVIGATION_COMPONENTS -->
<!-- SETTINGS: TRANSLUCENT_NAVIGATION_BAR
<SwitchPreference android:title="@string/revanced_enable_translucent_navigation_bar_title" android:key="revanced_enable_translucent_navigation_bar" android:summaryOn="@string/revanced_enable_translucent_navigation_bar_summary_on" android:summaryOff="@string/revanced_enable_translucent_navigation_bar_summary_off" />SETTINGS: TRANSLUCENT_NAVIGATION_BAR -->
<SwitchPreference android:title="@string/revanced_disable_translucent_navigation_bar_light_title" android:key="revanced_disable_translucent_navigation_bar_light" android:summaryOn="@string/revanced_disable_translucent_navigation_bar_light_summary_on" android:summaryOff="@string/revanced_disable_translucent_navigation_bar_light_summary_off" />
<SwitchPreference android:title="@string/revanced_disable_translucent_navigation_bar_dark_title" android:key="revanced_disable_translucent_navigation_bar_dark" android:summaryOn="@string/revanced_disable_translucent_navigation_bar_dark_summary_on" android:summaryOff="@string/revanced_disable_translucent_navigation_bar_dark_summary_off" />SETTINGS: TRANSLUCENT_NAVIGATION_BAR -->
<!-- SETTINGS: HIDE_NAVIGATION_COMPONENTS
<SwitchPreference android:title="@string/revanced_hide_navigation_bar_title" android:key="revanced_hide_navigation_bar" android:summaryOn="@string/revanced_hide_navigation_bar_summary_on" android:summaryOff="@string/revanced_hide_navigation_bar_summary_off" />