Skip to content

Commit

Permalink
feat(YouTube/Navigation bar components): add Hide navigation bar se…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
inotia00 committed Sep 25, 2024
1 parent e8ad2e6 commit 6c060c5
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import app.revanced.patches.youtube.general.navigation.fingerprints.TranslucentN
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.integrations.Constants.GENERAL_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.navigation.NavigationBarHookPatch
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand All @@ -30,6 +31,7 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(
description = "Adds options to hide or change components related to the navigation bar.",
dependencies = setOf(
SettingsPatch::class,
SharedResourceIdPatch::class,
NavigationBarHookPatch::class
),
compatiblePackages = COMPATIBLE_PACKAGE,
Expand Down Expand Up @@ -84,6 +86,12 @@ object NavigationBarComponentsPatch : BaseBytecodePatch(

// endregion

// region patch for hide navigation bar

NavigationBarHookPatch.addBottomBarContainerHook("$GENERAL_CLASS_DESCRIPTOR->hideNavigationBar(Landroid/view/View;)V")

// endregion

// region patch for hide navigation buttons

AutoMotiveFingerprint.resultOrThrow().let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_preference_screen_hook_buttons",
"revanced_preference_screen_import_export",
"revanced_preference_screen_miniplayer",
"revanced_preference_screen_navigation_buttons",
"revanced_preference_screen_navigation_bar",
"revanced_preference_screen_patch_information",
"revanced_preference_screen_player_buttons",
"revanced_preference_screen_player_flyout_menu",
Expand Down Expand Up @@ -418,7 +418,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_shorts_comments_button" -> "revanced_hide_quick_actions_comment_button_icon"
"revanced_hide_shorts_dislike_button" -> "revanced_preference_screen_ryd_icon"
"revanced_hide_shorts_like_button" -> "revanced_hide_quick_actions_like_button_icon"
"revanced_hide_shorts_navigation_bar" -> "revanced_preference_screen_navigation_buttons_icon"
"revanced_hide_shorts_navigation_bar" -> "revanced_preference_screen_navigation_bar_icon"
"revanced_hide_shorts_shelf_home_related_videos" -> "revanced_hide_navigation_home_button_icon"
"revanced_hide_shorts_shelf_subscriptions" -> "revanced_hide_navigation_subscriptions_button_icon"
"revanced_hide_shorts_toolbar" -> "revanced_preference_screen_toolbar_icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patches.youtube.shorts.components.fingerprints.BottomNavigationBarFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.RenderBottomNavigationBarFingerprint
import app.revanced.patches.youtube.shorts.components.fingerprints.SetPivotBarFingerprint
import app.revanced.patches.youtube.utils.fingerprints.InitializeButtonsFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_CLASS_DESCRIPTOR
import app.revanced.patches.youtube.utils.navigation.fingerprints.InitializeButtonsFingerprint
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.utils.fingerprints.InitializeButtonsFingerprint
import app.revanced.patches.youtube.utils.integrations.Constants.SHARED_PATH
import app.revanced.patches.youtube.utils.mainactivity.MainActivityResolvePatch
import app.revanced.patches.youtube.utils.navigation.fingerprints.InitializeBottomBarContainerFingerprint
import app.revanced.patches.youtube.utils.navigation.fingerprints.InitializeButtonsFingerprint
import app.revanced.patches.youtube.utils.navigation.fingerprints.NavigationEnumFingerprint
import app.revanced.patches.youtube.utils.navigation.fingerprints.PivotBarButtonsCreateDrawableViewFingerprint
import app.revanced.patches.youtube.utils.navigation.fingerprints.PivotBarButtonsCreateResourceViewFingerprint
Expand Down Expand Up @@ -39,6 +40,7 @@ import com.android.tools.smali.dexlib2.util.MethodUtil
@Suppress("unused")
object NavigationBarHookPatch : BytecodePatch(
setOf(
InitializeBottomBarContainerFingerprint,
NavigationEnumFingerprint,
PivotBarButtonsCreateDrawableViewFingerprint,
PivotBarButtonsCreateResourceViewFingerprint,
Expand All @@ -53,6 +55,10 @@ object NavigationBarHookPatch : BytecodePatch(

private lateinit var navigationTabCreatedCallback: MutableMethod

private lateinit var bottomBarContainerMethod: MutableMethod
private var bottomBarContainerIndex = 0
private var bottomBarContainerRegister = 0

override fun execute(context: BytecodeContext) {
fun MutableMethod.addHook(hook: Hook, insertPredicate: Instruction.() -> Boolean) {
val filtered = getInstructions().filter(insertPredicate)
Expand Down Expand Up @@ -124,6 +130,14 @@ object NavigationBarHookPatch : BytecodePatch(
INTEGRATIONS_CLASS_DESCRIPTOR,
"onBackPressed"
)

InitializeBottomBarContainerFingerprint.resultOrThrow().mutableMethod.apply {
bottomBarContainerMethod = this
bottomBarContainerIndex =
InitializeBottomBarContainerFingerprint.indexOfLayoutChangeListenerInstruction(this)
bottomBarContainerRegister =
getInstruction<FiveRegisterInstruction>(bottomBarContainerIndex).registerC
}
}

val hookNavigationButtonCreated: (String) -> Unit by lazy {
Expand All @@ -138,6 +152,12 @@ object NavigationBarHookPatch : BytecodePatch(
}
}

fun addBottomBarContainerHook(descriptor: String) =
bottomBarContainerMethod.addInstruction(
bottomBarContainerIndex,
"invoke-static { v$bottomBarContainerRegister }, $descriptor"
)

private enum class Hook(val methodName: String, val parameters: String) {
SET_LAST_APP_NAVIGATION_ENUM("setLastAppNavigationEnum", "Ljava/lang/Enum;"),
NAVIGATION_TAB_LOADED("navigationTabLoaded", "Landroid/view/View;"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package app.revanced.patches.youtube.utils.navigation.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patches.youtube.utils.navigation.fingerprints.InitializeBottomBarContainerFingerprint.indexOfLayoutChangeListenerInstruction
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.BottomBarContainer
import app.revanced.util.containsWideLiteralInstructionValue
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.Method
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

internal object InitializeBottomBarContainerFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
customFingerprint = { methodDef, classDef ->
AccessFlags.SYNTHETIC.isSet(classDef.accessFlags) &&
methodDef.containsWideLiteralInstructionValue(BottomBarContainer) &&
indexOfLayoutChangeListenerInstruction(methodDef) >= 0
},
) {
fun indexOfLayoutChangeListenerInstruction(methodDef: Method) =
methodDef.indexOfFirstInstruction {
opcode == Opcode.INVOKE_VIRTUAL &&
getReference<MethodReference>()?.toString() == "Landroid/view/View;->addOnLayoutChangeListener(Landroid/view/View${'$'}OnLayoutChangeListener;)V"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app.revanced.patches.youtube.utils.fingerprints
package app.revanced.patches.youtube.utils.navigation.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ImageOnlyTab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var BadgeLabel = -1L
var Bar = -1L
var BarContainerHeight = -1L
var BottomBarContainer = -1L
var BottomSheetFooterText = -1L
var BottomSheetRecyclerView = -1L
var BottomUiContainerStub = -1L
Expand Down Expand Up @@ -136,6 +137,7 @@ object SharedResourceIdPatch : ResourcePatch() {
BadgeLabel = getId(ID, "badge_label")
Bar = getId(LAYOUT, "bar")
BarContainerHeight = getId(DIMEN, "bar_container_height")
BottomBarContainer = getId(ID, "bottom_bar_container")
BottomSheetFooterText = getId(ID, "bottom_sheet_footer_text")
BottomSheetRecyclerView = getId(LAYOUT, "bottom_sheet_recycler_view")
BottomUiContainerStub = getId(ID, "bottom_ui_container_stub")
Expand Down
9 changes: 6 additions & 3 deletions src/main/resources/youtube/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ Some components may not be hidden."</string>
<string name="revanced_miniplayer_opacity_summary">Opacity value between 0-100, where 0 is transparent.</string>
<string name="revanced_miniplayer_opacity_invalid_toast">Miniplayer overlay opacity must be between 0-100.</string>

<!-- PreferenceScreen: General, PreferenceCategory: General, PreferenceScreen: Navigation buttons -->
<string name="revanced_preference_screen_navigation_buttons_title">Navigation buttons</string>
<string name="revanced_preference_screen_navigation_buttons_summary">Hide or show navigation bar section components.</string>
<!-- PreferenceScreen: General, PreferenceCategory: General, PreferenceScreen: Navigation bar -->
<string name="revanced_preference_screen_navigation_bar_title">Navigation bar</string>
<string name="revanced_preference_screen_navigation_bar_summary">Hide or show navigation bar section components.</string>

<string name="revanced_enable_narrow_navigation_buttons_title">Enable narrow navigation buttons</string>
<string name="revanced_enable_narrow_navigation_buttons_summary_on">Spacing between navigation buttons is narrow.</string>
Expand Down Expand Up @@ -508,6 +508,9 @@ 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_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>

<!-- PreferenceScreen: General, PreferenceCategory: General, PreferenceScreen: Settings menu -->
<string name="revanced_preference_screen_settings_menu_title">Settings menu</string>
Expand Down
10 changes: 6 additions & 4 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
</PreferenceScreen>SETTINGS: MINIPLAYER_TYPE_MODERN -->

<!-- SETTINGS: HIDE_NAVIGATION_COMPONENTS
<PreferenceScreen android:title="@string/revanced_preference_screen_navigation_buttons_title" android:key="revanced_preference_screen_navigation_buttons" android:summary="@string/revanced_preference_screen_navigation_buttons_summary">
<PreferenceScreen android:title="@string/revanced_preference_screen_navigation_bar_title" android:key="revanced_preference_screen_navigation_bar" android:summary="@string/revanced_preference_screen_navigation_bar_summary">
<SwitchPreference android:title="@string/revanced_enable_narrow_navigation_buttons_title" android:key="revanced_enable_narrow_navigation_buttons" android:summaryOn="@string/revanced_enable_narrow_navigation_buttons_summary_on" android:summaryOff="@string/revanced_enable_narrow_navigation_buttons_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_navigation_create_button_title" android:key="revanced_hide_navigation_create_button" android:summaryOn="@string/revanced_hide_navigation_create_button_summary_on" android:summaryOff="@string/revanced_hide_navigation_create_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_navigation_home_button_title" android:key="revanced_hide_navigation_home_button" android:summaryOn="@string/revanced_hide_navigation_home_button_summary_on" android:summaryOff="@string/revanced_hide_navigation_home_button_summary_off" />
Expand All @@ -181,13 +181,15 @@
<SwitchPreference android:title="@string/revanced_hide_navigation_shorts_button_title" android:key="revanced_hide_navigation_shorts_button" android:summaryOn="@string/revanced_hide_navigation_shorts_button_summary_on" android:summaryOff="@string/revanced_hide_navigation_shorts_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_navigation_subscriptions_button_title" android:key="revanced_hide_navigation_subscriptions_button" android:summaryOn="@string/revanced_hide_navigation_subscriptions_button_summary_on" android:summaryOff="@string/revanced_hide_navigation_subscriptions_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_navigation_label_title" android:key="revanced_hide_navigation_label" android:summaryOn="@string/revanced_hide_navigation_label_summary_on" android:summaryOff="@string/revanced_hide_navigation_label_summary_off" />
<SwitchPreference android:title="@string/revanced_switch_create_with_notifications_button_title" android:key="revanced_switch_create_with_notifications_button" android:summaryOn="@string/revanced_switch_create_with_notifications_button_summary_on" android:summaryOff="@string/revanced_switch_create_with_notifications_button_summary_off" />SETTINGS: HIDE_NAVIGATION_COMPONENTS -->
<SwitchPreference android:title="@string/revanced_switch_create_with_notifications_button_title" android:key="revanced_switch_create_with_notifications_button" android:summaryOn="@string/revanced_switch_create_with_notifications_button_summary_on" android:summaryOff="@string/revanced_switch_create_with_notifications_button_summary_off" />
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>SETTINGS: HIDE_NAVIGATION_COMPONENTS -->

<!-- SETTINGS: TRANSLUCENT_NAVIGATION_BAR
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>
<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 -->

<!-- SETTINGS: HIDE_NAVIGATION_COMPONENTS
<!-- 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" />
</PreferenceScreen>SETTINGS: HIDE_NAVIGATION_COMPONENTS -->

<!-- SETTINGS: HIDE_LAYOUT_COMPONENTS
Expand Down

0 comments on commit 6c060c5

Please sign in to comment.