generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(youtube):
hide-floating-microphone-button
patch
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...e/layout/hide/floatingmicrophone/annotations/HideFloatingMicrophoneButtonCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.google.android.youtube", arrayOf("17.49.37", "18.03.36") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class HideFloatingMicrophoneButtonCompatibility |
19 changes: 19 additions & 0 deletions
19
...be/layout/hide/floatingmicrophone/fingerprints/ShowFloatingMicrophoneButtonFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
import app.revanced.patches.youtube.layout.hide.floatingmicrophone.patch.HideFloatingMicrophoneButtonResourcePatch | ||
import org.jf.dexlib2.Opcode | ||
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction | ||
|
||
object ShowFloatingMicrophoneButtonFingerprint : MethodFingerprint( | ||
opcodes = listOf( | ||
Opcode.IGET_BOOLEAN, | ||
Opcode.IF_EQZ, | ||
Opcode.RETURN_VOID | ||
), | ||
customFingerprint = { methodDef -> | ||
methodDef.implementation?.instructions?.any { | ||
(it as? WideLiteralInstruction)?.wideLiteral == HideFloatingMicrophoneButtonResourcePatch.fabButtonId | ||
} == true | ||
} | ||
) |
51 changes: 51 additions & 0 deletions
51
...patches/youtube/layout/hide/floatingmicrophone/patch/HideFloatingMicrophoneButtonPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.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.youtube.layout.hide.floatingmicrophone.annotations.HideFloatingMicrophoneButtonCompatibility | ||
import app.revanced.patches.youtube.layout.hide.floatingmicrophone.fingerprints.ShowFloatingMicrophoneButtonFingerprint | ||
import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch | ||
@Name("hide-floating-microphone-button") | ||
@Description("Hides the floating microphone button which appears in search.") | ||
@DependsOn([HideFloatingMicrophoneButtonResourcePatch::class]) | ||
@HideFloatingMicrophoneButtonCompatibility | ||
@Version("0.0.1") | ||
class HideFloatingMicrophoneButtonPatch : BytecodePatch( | ||
listOf(ShowFloatingMicrophoneButtonFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext): PatchResult { | ||
ShowFloatingMicrophoneButtonFingerprint.result?.let { result -> | ||
with(result.mutableMethod) { | ||
val insertIndex = result.scanResult.patternScanResult!!.startIndex + 1 | ||
val showButtonRegister = (instruction(insertIndex - 1) as TwoRegisterInstruction).registerA | ||
|
||
addInstructions( | ||
insertIndex, | ||
""" | ||
invoke-static {v$showButtonRegister}, $INTEGRATIONS_CLASS_DESCRIPTOR->hideFloatingMicrophoneButton(Z)Z | ||
move-result v$showButtonRegister | ||
""" | ||
) | ||
} | ||
} ?: return ShowFloatingMicrophoneButtonFingerprint.toErrorResult() | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"Lapp/revanced/integrations/patches/HideFloatingMicrophoneButtonPatch;" | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...youtube/layout/hide/floatingmicrophone/patch/HideFloatingMicrophoneButtonResourcePatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package app.revanced.patches.youtube.layout.hide.floatingmicrophone.patch | ||
|
||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultError | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotations.DependsOn | ||
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.hide.floatingmicrophone.annotations.HideFloatingMicrophoneButtonCompatibility | ||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch | ||
|
||
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) | ||
@HideFloatingMicrophoneButtonCompatibility | ||
@Version("0.0.1") | ||
class HideFloatingMicrophoneButtonResourcePatch : ResourcePatch { | ||
override fun execute(context: ResourceContext): PatchResult { | ||
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( | ||
SwitchPreference( | ||
"revanced_hide_floating_microphone_button", | ||
StringResource( | ||
"revanced_hide_floating_microphone_button_enabled_title", | ||
"Hide floating microphone button" | ||
), | ||
true, | ||
StringResource("revanced_hide_floating_microphone_button_summary_on", "Microphone button hidden"), | ||
StringResource("revanced_hide_floating_microphone_button_summary_off", "Microphone button shown") | ||
) | ||
) | ||
|
||
fabButtonId = ResourceMappingPatch.resourceMappings.find { it.type == "id" && it.name == "fab" }?.id | ||
?: return PatchResultError("Can not find required fab button resource id") | ||
return PatchResultSuccess() | ||
} | ||
|
||
internal companion object { | ||
var fabButtonId: Long = -1 | ||
} | ||
} |