From 385ceda61f586f24b11a284688f55758ef5b4e74 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 2 May 2023 06:58:18 +0200 Subject: [PATCH] feat(youtube/create-button): switch create with notifications button --- .../AddCreateButtonViewFingerprint.kt | 12 +++++ ...onRemoverPatch.kt => CreateButtonPatch.kt} | 49 +++++++++++++++++-- 2 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/fingerprints/AddCreateButtonViewFingerprint.kt rename src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/{CreateButtonRemoverPatch.kt => CreateButtonPatch.kt} (61%) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/fingerprints/AddCreateButtonViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/fingerprints/AddCreateButtonViewFingerprint.kt new file mode 100644 index 000000000..3ba169473 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/fingerprints/AddCreateButtonViewFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.youtube.layout.buttons.pivotbar.create.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +internal const val ANDROID_AUTOMOTIVE_STRING = "Android Automotive" + +object AddCreateButtonViewFingerprint : MethodFingerprint( + strings = listOf( + "Android Wear", + ANDROID_AUTOMOTIVE_STRING, + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonRemoverPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonPatch.kt similarity index 61% rename from src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonRemoverPatch.kt rename to src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonPatch.kt index ae37a4665..eb034764b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonRemoverPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/pivotbar/create/patch/CreateButtonPatch.kt @@ -5,6 +5,8 @@ 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 @@ -14,6 +16,8 @@ import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch import app.revanced.patches.shared.settings.preference.impl.StringResource import app.revanced.patches.shared.settings.preference.impl.SwitchPreference +import app.revanced.patches.youtube.layout.buttons.pivotbar.create.fingerprints.ANDROID_AUTOMOTIVE_STRING +import app.revanced.patches.youtube.layout.buttons.pivotbar.create.fingerprints.AddCreateButtonViewFingerprint import app.revanced.patches.youtube.layout.buttons.pivotbar.create.fingerprints.PivotBarCreateButtonViewFingerprint import app.revanced.patches.youtube.layout.buttons.pivotbar.shared.annotations.PivotBarCompatibility import app.revanced.patches.youtube.layout.buttons.pivotbar.shared.fingerprints.InitializeButtonsFingerprint @@ -23,16 +27,17 @@ import app.revanced.patches.youtube.layout.buttons.pivotbar.utils.InjectionUtils import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import org.jf.dexlib2.Opcode +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @DependsOn([IntegrationsPatch::class, ResourceMappingPatch::class, SettingsPatch::class, ResolvePivotBarFingerprintsPatch::class]) -@Name("hide-create-button") -@Description("Hides the create button in the navigation bar.") +@Name("create-button") +@Description("Hide the create button in the navigation bar or switch it with notifications.") @PivotBarCompatibility @Version("0.0.1") -class CreateButtonRemoverPatch : BytecodePatch() { +class CreateButtonPatch : BytecodePatch(listOf(AddCreateButtonViewFingerprint)) { private companion object { - const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/HideCreateButtonPatch;" + const val INTEGRATIONS_CLASS_DESCRIPTOR = "Lapp/revanced/integrations/patches/CreateButtonPatch;" } override fun execute(context: BytecodeContext): PatchResult { @@ -43,9 +48,43 @@ class CreateButtonRemoverPatch : BytecodePatch() { true, StringResource("revanced_hide_create_button_summary_on", "Create button is hidden"), StringResource("revanced_hide_create_button_summary_off", "Create button is shown") - ) + ), + SwitchPreference( + "revanced_switch_create_with_notifications_button", + StringResource( + "revanced_switch_create_with_notifications_button_title", + "Switch create with notifications button" + ), + true, + StringResource( + "revanced_switch_create_with_notifications_button_summary_on", + "Create button is switched with notifications" + ), + StringResource( + "revanced_switch_create_with_notifications_button_summary_off", + "Create button is not switched with notifications" + ), + ), ) + AddCreateButtonViewFingerprint.result?.let { + it.mutableMethod.apply { + val stringIndex = it.scanResult.stringsScanResult!!.matches.find { + match -> match.string == ANDROID_AUTOMOTIVE_STRING + }!!.index + + val conditionalCheckIndex = stringIndex - 1 + val conditionRegister = (instruction(conditionalCheckIndex) as OneRegisterInstruction).registerA + + addInstructions( + conditionalCheckIndex, + """ + invoke-static { }, $INTEGRATIONS_CLASS_DESCRIPTOR->switchCreateWithNotificationButton()Z + move-result v$conditionRegister + """ + ) + } + } ?: return AddCreateButtonViewFingerprint.toErrorResult() /* * Resolve fingerprints */