add enable-tablet-navigation-bar patch

This commit is contained in:
inotia00 2023-04-02 19:13:53 +09:00
parent 5ffed2d934
commit 35a52a0ee9
5 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,14 @@
package app.revanced.patches.youtube.layout.navigation.tabletnavbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object PivotBarChangedFingerprint : MethodFingerprint(
returnType = "V",
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT
),
customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;"
&& it.name == "onConfigurationChanged" }
)

View File

@ -0,0 +1,15 @@
package app.revanced.patches.youtube.layout.navigation.tabletnavbar.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.Opcode
object PivotBarStyleFingerprint : MethodFingerprint(
returnType = "V",
parameters = listOf("L"),
opcodes = listOf(
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT,
Opcode.XOR_INT_2ADDR
),
customFingerprint = { it.definingClass == "Lcom/google/android/apps/youtube/app/ui/pivotbar/PivotBar;" }
)

View File

@ -0,0 +1,70 @@
package app.revanced.patches.youtube.layout.navigation.tabletnavbar.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.MethodFingerprintResult
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.tabletnavbar.fingerprints.*
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("enable-tablet-navigation-bar")
@Description("Enables the tablet navigation bar.")
@DependsOn([SettingsPatch::class])
@YouTubeCompatibility
@Version("0.0.1")
class TabletNavigationBarPatch : BytecodePatch(
listOf(
PivotBarChangedFingerprint,
PivotBarStyleFingerprint
)
) {
override fun execute(context: BytecodeContext): PatchResult {
arrayOf(
PivotBarChangedFingerprint,
PivotBarStyleFingerprint
).forEach {
it.result?.insertHook() ?: return it.toErrorResult()
}
/*
* Add settings
*/
SettingsPatch.addPreference(
arrayOf(
"PREFERENCE: NAVIGATION_SETTINGS",
"SETTINGS: ENABLE_TABLET_NAVIGATION_BAR"
)
)
SettingsPatch.updatePatchStatus("enable-tablet-navigation-bar")
return PatchResultSuccess()
}
companion object {
private fun MethodFingerprintResult.insertHook() {
val targetIndex = this.scanResult.patternScanResult!!.startIndex + 1
val register = (mutableMethod.instruction(targetIndex) as OneRegisterInstruction).registerA
mutableMethod.addInstructions(
targetIndex + 1, """
invoke-static {v$register}, $NAVIGATION->enableTabletNavBar(Z)Z
move-result v$register
"""
)
}
}
}

View File

@ -245,6 +245,9 @@ Is it ready to submit?"</string>
<string name="revanced_enable_tablet_miniplayer_summary_off">Tablet mini player is disabled</string>
<string name="revanced_enable_tablet_miniplayer_summary_on">Tablet mini player is enabled</string>
<string name="revanced_enable_tablet_miniplayer_title">Enable tablet mini player</string>
<string name="revanced_enable_tablet_navigation_bar_summary_off">Tablet navigation bar is disabled</string>
<string name="revanced_enable_tablet_navigation_bar_summary_on">Tablet navigation bar is enabled</string>
<string name="revanced_enable_tablet_navigation_bar_title">Enable tablet navigation bar</string>
<string name="revanced_enable_time_stamp_speed_summary_off">Append time stamp speed is disabled</string>
<string name="revanced_enable_time_stamp_speed_summary_on">Append time stamp speed is enabled</string>
<string name="revanced_enable_time_stamp_speed_title">Enable time stamp speed</string>

View File

@ -293,6 +293,9 @@
<PreferenceScreen android:title="@string/revanced_navigation" android:key="navigation">
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_navigation" />PREFERENCE: NAVIGATION_SETTINGS -->
<!-- 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 -->
@ -481,6 +484,7 @@
<Preference android:title="hide-flyout-panel" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_navigation" />
<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-shorts-button" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>