feat(hide-navigation-buttons): combined hide-create-button, hide-home-button, hide-shorts-button, hide-subscriptions-button, switch-create-notification patches into one

This commit is contained in:
inotia00 2023-05-03 18:39:35 +09:00
parent faadde5334
commit 77a9ae38f6
11 changed files with 90 additions and 301 deletions

View File

@ -1,74 +0,0 @@
package app.revanced.patches.youtube.layout.navigation.createbutton.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.PivotBarCreateButtonViewFingerprint
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.NAVIGATION
import app.revanced.util.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.pivotbar.InjectionUtils.injectHook
import org.jf.dexlib2.Opcode
@Patch
@Name("hide-create-button")
@Description("Hides the create button in the navigation bar.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class CreateButtonRemoverPatch : BytecodePatch(
listOf(
PivotBarCreateButtonViewFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
PivotBarCreateButtonViewFingerprint.result?.let { result ->
with (result.mutableMethod) {
val insertIndex = implementation!!.instructions.let {
val scanStart = result.scanResult.patternScanResult!!.endIndex
scanStart + it.subList(scanStart, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_STATIC
}
}
injectHook(hook, insertIndex)
}
} ?: return PivotBarCreateButtonViewFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: HIDE_CREATE_BUTTON"
)
)
SettingsPatch.updatePatchStatus("hide-create-button")
return PatchResultSuccess()
}
private companion object {
const val hook =
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $NAVIGATION" +
"->" +
"hideCreateButton(Landroid/view/View;)V"
}
}

View File

@ -1,44 +0,0 @@
package app.revanced.patches.youtube.layout.navigation.homebutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.lastpivottab.patch.LastPivotTabHookPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
@Patch
@Name("hide-home-button")
@Description("Hides the home button in the navigation bar.")
@DependsOn(
[
SettingsPatch::class,
LastPivotTabHookPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class HomeButtonRemoverPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: HIDE_HOME_BUTTON"
)
)
SettingsPatch.updatePatchStatus("hide-home-button")
return PatchResultSuccess()
}
}

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.layout.navigation.switchbutton.fingerprints
package app.revanced.patches.youtube.layout.navigation.navigationbuttons.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.lastpivottab.fingerprints
package app.revanced.patches.youtube.layout.navigation.navigationbuttons.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

View File

@ -1,4 +1,4 @@
package app.revanced.patches.youtube.misc.lastpivottab.fingerprints
package app.revanced.patches.youtube.layout.navigation.navigationbuttons.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode

View File

@ -1,37 +1,53 @@
package app.revanced.patches.youtube.misc.lastpivottab.patch
package app.revanced.patches.youtube.layout.navigation.navigationbuttons.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.PivotBarCreateButtonViewFingerprint
import app.revanced.patches.youtube.misc.lastpivottab.fingerprints.PivotBarEnumFingerprint
import app.revanced.patches.youtube.misc.lastpivottab.fingerprints.PivotBarShortsButtonViewFingerprint
import app.revanced.patches.youtube.layout.navigation.navigationbuttons.fingerprints.*
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.NAVIGATION
import app.revanced.util.pivotbar.InjectionUtils.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.pivotbar.InjectionUtils.injectHook
import org.jf.dexlib2.Opcode
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Name("last-pivot-tab-hook")
@DependsOn([SharedResourceIdPatch::class])
@Patch
@Name("hide-navigation-buttons")
@Description("Adds options to hide or change navigation buttons.")
@DependsOn(
[
SettingsPatch::class,
SharedResourceIdPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class LastPivotTabHookPatch : BytecodePatch(
listOf(PivotBarCreateButtonViewFingerprint)
class NavigationButtonsPatch : BytecodePatch(
listOf(
AutoMotiveFingerprint,
PivotBarCreateButtonViewFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
/*
* Resolve fingerprints
*/
PivotBarCreateButtonViewFingerprint.result?.let { parentResult ->
/**
* Home, Shorts, Subscriptions Button
*/
with (
arrayOf(
PivotBarEnumFingerprint,
@ -60,8 +76,51 @@ class LastPivotTabHookPatch : BytecodePatch(
}
}
/**
* Create Button
*/
with (parentResult.mutableMethod) {
val insertIndex = implementation!!.instructions.let {
val scanStart = parentResult.scanResult.patternScanResult!!.endIndex
scanStart + it.subList(scanStart, it.size - 1).indexOfFirst { instruction ->
instruction.opcode == Opcode.INVOKE_STATIC
}
}
injectHook(createButtonHook, insertIndex)
}
} ?: return PivotBarCreateButtonViewFingerprint.toErrorResult()
/*
* Switch create button with notifications button
*/
AutoMotiveFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val register = (instruction(insertIndex) as OneRegisterInstruction).registerA
addInstructions(
insertIndex, """
invoke-static {v$register}, $NAVIGATION->switchCreateNotification(Z)Z
move-result v$register
"""
)
}
} ?: return AutoMotiveFingerprint.toErrorResult()
/**
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: HIDE_NAVIGATION_BUTTONS"
)
)
SettingsPatch.updatePatchStatus("hide-navigation-buttons")
return PatchResultSuccess()
}
private companion object {
@ -74,5 +133,10 @@ class LastPivotTabHookPatch : BytecodePatch(
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $NAVIGATION" +
"->" +
"hideNavigationButton(Landroid/view/View;)V"
const val createButtonHook =
"invoke-static { v$REGISTER_TEMPLATE_REPLACEMENT }, $NAVIGATION" +
"->" +
"hideCreateButton(Landroid/view/View;)V"
}
}

View File

@ -1,44 +0,0 @@
package app.revanced.patches.youtube.layout.navigation.shortsbutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.lastpivottab.patch.LastPivotTabHookPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
@Patch
@Name("hide-shorts-button")
@Description("Hides the shorts button in the navigation bar.")
@DependsOn(
[
SettingsPatch::class,
LastPivotTabHookPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class ShortsButtonRemoverPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: HIDE_SHORTS_BUTTON"
)
)
SettingsPatch.updatePatchStatus("hide-shorts-button")
return PatchResultSuccess()
}
}

View File

@ -1,44 +0,0 @@
package app.revanced.patches.youtube.layout.navigation.subscriptionsbutton.patch
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.lastpivottab.patch.LastPivotTabHookPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
@Patch
@Name("hide-subscriptions-button")
@Description("Hides the subscriptions button in the navigation bar.")
@DependsOn(
[
SettingsPatch::class,
LastPivotTabHookPatch::class
]
)
@YouTubeCompatibility
@Version("0.0.1")
class SubscriptionsButtonRemoverPatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: HIDE_SUBSCRIPTIONS_BUTTON"
)
)
SettingsPatch.updatePatchStatus("hide-subscriptions-button")
return PatchResultSuccess()
}
}

View File

@ -1,60 +0,0 @@
package app.revanced.patches.youtube.layout.navigation.switchbutton.patch
import app.revanced.extensions.toErrorResult
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.layout.navigation.switchbutton.fingerprints.AutoMotiveFingerprint
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.NAVIGATION
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@Patch
@Name("switch-create-notification")
@Description("Switching the create button and notification button.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class SwitchCreateButtonPatch : BytecodePatch(
listOf(AutoMotiveFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
AutoMotiveFingerprint.result?.let {
with (it.mutableMethod) {
val insertIndex = it.scanResult.patternScanResult!!.endIndex
val register = (instruction(insertIndex) as OneRegisterInstruction).registerA
addInstructions(
insertIndex, """
invoke-static {v$register}, $NAVIGATION->switchCreateNotification(Z)Z
move-result v$register
"""
)
}
} ?: return AutoMotiveFingerprint.toErrorResult()
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: SWITCH_CREATE_NOTIFICATION"
)
)
SettingsPatch.updatePatchStatus("switch-create-notification")
return PatchResultSuccess()
}
}

View File

@ -411,14 +411,15 @@ Please do not report any issues you encounter while using this feature."</string
<string name="revanced_hide_shorts_shelf_summary_off">Shorts shelves are shown</string>
<string name="revanced_hide_shorts_shelf_summary_on">Shorts shelves are hidden</string>
<string name="revanced_hide_shorts_shelf_title">Hide shorts shelf</string>
<string name="revanced_shorts">Shorts</string>
<string name="revanced_shorts_player_title">Shorts player</string>
<string name="revanced_hide_snackbar_summary_off">Snackbar is shown</string>
<string name="revanced_hide_snackbar_summary_on">Snackbar is hidden</string>
<string name="revanced_hide_snackbar_title">Hide snackbar</string>
<string name="revanced_hide_stories_shelf_summary_off">Stories shelves are shown</string>
<string name="revanced_hide_stories_shelf_summary_on">Stories shelves are hidden</string>
<string name="revanced_hide_stories_shelf_title">Hide stories shelf</string>
<string name="revanced_hide_subscriptions_button_summary_off">Subscriptions button is shown</string>
<string name="revanced_hide_subscriptions_button_summary_on">Subscriptions button is hidden</string>
<string name="revanced_hide_subscriptions_button_title">Hide subscriptions button</string>
<string name="revanced_hide_suggested_actions_summary_off">Suggested actions shown</string>
<string name="revanced_hide_suggested_actions_summary_on">Suggested actions hidden</string>
<string name="revanced_hide_suggested_actions_title">Hide suggested actions</string>
@ -513,6 +514,8 @@ Since these setting is quite outdated, it may not be valid"</string>
<string name="revanced_save_video_quality_wifi">Changing default Wi-Fi quality to:</string>
<string name="revanced_save_video_speed">Changing default speed to:</string>
<string name="revanced_seekbar">Seekbar</string>
<string name="revanced_shorts">Shorts</string>
<string name="revanced_shorts_player_title">Shorts player</string>
<string name="revanced_show_fullscreen_title_summary">Known issue: Title disappears when clicked</string>
<string name="revanced_show_fullscreen_title_title">Show fullscreen title</string>
<string name="revanced_sponsorblock_settings_summary">SponsorBlock related settings</string>

View File

@ -320,20 +320,12 @@
<!-- SETTINGS: ENABLE_TABLET_NAVIGATION_BAR
<SwitchPreference android:title="@string/revanced_enable_tablet_navigation_bar_title" android:key="revanced_enable_tablet_navigation_bar" android:defaultValue="false" android:summaryOn="@string/revanced_enable_tablet_navigation_bar_summary_on" android:summaryOff="@string/revanced_enable_tablet_navigation_bar_summary_off" />SETTINGS: ENABLE_TABLET_NAVIGATION_BAR -->
<!-- SETTINGS: SWITCH_CREATE_NOTIFICATION
<SwitchPreference android:title="@string/revanced_switching_create_notification_title" android:key="revanced_switching_create_notification" android:defaultValue="false" android:summaryOn="@string/revanced_switching_create_notification_summary_on" android:summaryOff="@string/revanced_switching_create_notification_summary_off" />SETTINGS: SWITCH_CREATE_NOTIFICATION -->
<!-- SETTINGS: HIDE_CREATE_BUTTON
<SwitchPreference android:title="@string/revanced_hide_create_button_title" android:key="revanced_hide_create_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_create_button_summary_on" android:summaryOff="@string/revanced_hide_create_button_summary_off" />SETTINGS: HIDE_CREATE_BUTTON -->
<!-- SETTINGS: HIDE_HOME_BUTTON
<SwitchPreference android:title="@string/revanced_hide_home_button_title" android:key="revanced_hide_home_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_home_button_summary_on" android:summaryOff="@string/revanced_hide_home_button_summary_off" />SETTINGS: HIDE_HOME_BUTTON -->
<!-- SETTINGS: HIDE_SHORTS_BUTTON
<SwitchPreference android:title="@string/revanced_hide_shorts_button_title" android:key="revanced_hide_shorts_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_button_summary_off" />SETTINGS: HIDE_SHORTS_BUTTON -->
<!-- SETTINGS: HIDE_SUBSCRIPTIONS_BUTTON
<SwitchPreference android:title="@string/revanced_hide_subscriptions_button_title" android:key="revanced_hide_subscriptions_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_subscriptions_button_summary_on" android:summaryOff="@string/revanced_hide_subscriptions_button_summary_off" />SETTINGS: HIDE_SUBSCRIPTIONS_BUTTON -->
<!-- SETTINGS: HIDE_NAVIGATION_BUTTONS
<SwitchPreference android:title="@string/revanced_switching_create_notification_title" android:key="revanced_switching_create_notification" android:defaultValue="true" android:summaryOn="@string/revanced_switching_create_notification_summary_on" android:summaryOff="@string/revanced_switching_create_notification_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_create_button_title" android:key="revanced_hide_create_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_create_button_summary_on" android:summaryOff="@string/revanced_hide_create_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_home_button_title" android:key="revanced_hide_home_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_home_button_summary_on" android:summaryOff="@string/revanced_hide_home_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_button_title" android:key="revanced_hide_shorts_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_shorts_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_subscriptions_button_title" android:key="revanced_hide_subscriptions_button" android:defaultValue="false" android:summaryOn="@string/revanced_hide_subscriptions_button_summary_on" android:summaryOff="@string/revanced_hide_subscriptions_button_summary_off" />SETTINGS: HIDE_NAVIGATION_BUTTONS -->
<!-- SETTINGS: HIDE_SHORTS_NAVIGATION_BAR
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
@ -517,11 +509,7 @@
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_navigation" />
<Preference android:title="change-homepage" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="enable-tablet-navigation-bar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="switch-create-notification" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-create-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-home-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-shorts-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-subscriptions-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-navigation-buttons" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="hide-shorts-navbar" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_seekbar" />