feat(youtube/create-button): switch create with notifications button

This commit is contained in:
oSumAtrIX 2023-05-02 06:58:18 +02:00
parent 4559b69ec5
commit 385ceda61f
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 56 additions and 5 deletions

View File

@ -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,
)
)

View File

@ -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
*/