-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Shorts components): Add
Double-tap animation
settings
- Loading branch information
1 parent
234feb7
commit a1868ec
Showing
15 changed files
with
181 additions
and
68 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
...main/kotlin/app/revanced/patches/youtube/layout/animated/AnimatedButtonBackgroundPatch.kt
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
src/main/kotlin/app/revanced/patches/youtube/layout/animated/AnimatedLikePatch.kt
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
src/main/kotlin/app/revanced/patches/youtube/shorts/components/ShortsAnimationPatch.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,77 @@ | ||
package app.revanced.patches.youtube.shorts.components | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.youtube.shorts.components.fingerprints.ReelFeedbackFingerprint | ||
import app.revanced.patches.youtube.utils.integrations.Constants.SHORTS_PATH | ||
import app.revanced.patches.youtube.utils.lottie.LottieAnimationViewHookPatch | ||
import app.revanced.patches.youtube.utils.lottie.fingerprints.SetAnimationFingerprint.LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackLike | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackPause | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackPlay | ||
import app.revanced.patches.youtube.utils.settings.SettingsPatch.contexts | ||
import app.revanced.util.ResourceGroup | ||
import app.revanced.util.copyResources | ||
import app.revanced.util.getWideLiteralInstructionIndex | ||
import app.revanced.util.indexOfFirstInstructionOrThrow | ||
import app.revanced.util.resultOrThrow | ||
import com.android.tools.smali.dexlib2.Opcode | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction | ||
|
||
@Patch(dependencies = [LottieAnimationViewHookPatch::class]) | ||
object ShortsAnimationPatch : BytecodePatch( | ||
setOf(ReelFeedbackFingerprint) | ||
) { | ||
private const val INTEGRATION_CLASS_DESCRIPTOR = | ||
"$SHORTS_PATH/AnimationFeedbackPatch;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
|
||
ReelFeedbackFingerprint.resultOrThrow().let { | ||
it.mutableMethod.apply { | ||
mapOf( | ||
ReelFeedbackLike to "setShortsLikeFeedback", | ||
ReelFeedbackPause to "setShortsPauseFeedback", | ||
ReelFeedbackPlay to "setShortsPlayFeedback", | ||
).forEach { (literal, methodName) -> | ||
val literalIndex = getWideLiteralInstructionIndex(literal) | ||
val viewIndex = indexOfFirstInstructionOrThrow(literalIndex) { | ||
opcode == Opcode.CHECK_CAST | ||
&& (this as? ReferenceInstruction)?.reference?.toString() == LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR | ||
} | ||
val viewRegister = getInstruction<OneRegisterInstruction>(viewIndex).registerA | ||
val methodCall = "invoke-static {v$viewRegister}, " + | ||
INTEGRATION_CLASS_DESCRIPTOR + | ||
"->" + | ||
methodName + | ||
"($LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR)V" | ||
|
||
addInstruction( | ||
viewIndex + 1, | ||
methodCall | ||
) | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Copy json | ||
*/ | ||
contexts.copyResources( | ||
"youtube/shorts/feedback", | ||
ResourceGroup( | ||
"raw", | ||
"like_tap_feedback_cairo.json", | ||
"like_tap_feedback_heart.json", | ||
"like_tap_feedback_heart_tint.json", | ||
"like_tap_feedback_hidden.json", | ||
"pause_tap_feedback_hidden.json", | ||
"play_tap_feedback_hidden.json" | ||
) | ||
) | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
...in/app/revanced/patches/youtube/shorts/components/fingerprints/ReelFeedbackFingerprint.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,16 @@ | ||
package app.revanced.patches.youtube.shorts.components.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackLike | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackPause | ||
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ReelFeedbackPlay | ||
import app.revanced.util.containsWideLiteralInstructionIndex | ||
|
||
internal object ReelFeedbackFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.containsWideLiteralInstructionIndex(ReelFeedbackLike) | ||
&& methodDef.containsWideLiteralInstructionIndex(ReelFeedbackPause) | ||
&& methodDef.containsWideLiteralInstructionIndex(ReelFeedbackPlay) | ||
}, | ||
) |
40 changes: 40 additions & 0 deletions
40
src/main/kotlin/app/revanced/patches/youtube/utils/lottie/LottieAnimationViewHookPatch.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,40 @@ | ||
package app.revanced.patches.youtube.utils.lottie | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.PatchException | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH | ||
import app.revanced.patches.youtube.utils.lottie.fingerprints.SetAnimationFingerprint | ||
import app.revanced.patches.youtube.utils.lottie.fingerprints.SetAnimationFingerprint.LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR | ||
import app.revanced.util.resultOrThrow | ||
|
||
@Patch( | ||
description = "Hook YouTube to use LottieAnimationView.setAnimation in the integration.", | ||
) | ||
object LottieAnimationViewHookPatch : BytecodePatch( | ||
setOf(SetAnimationFingerprint) | ||
) { | ||
private const val INTEGRATIONS_CLASS_DESCRIPTOR = | ||
"$UTILS_PATH/LottieAnimationViewPatch;" | ||
|
||
override fun execute(context: BytecodeContext) { | ||
|
||
val setAnimationMethodName = SetAnimationFingerprint.resultOrThrow().mutableMethod.name | ||
val setAnimationCall = "invoke-virtual {p0, p1}, " + | ||
LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR + | ||
"->" + | ||
setAnimationMethodName + | ||
"(I)V" | ||
|
||
context.findClass(INTEGRATIONS_CLASS_DESCRIPTOR) | ||
?.mutableClass | ||
?.methods | ||
?.first { method -> method.name == "setAnimation" } | ||
?.addInstruction( | ||
0, | ||
setAnimationCall | ||
)?: throw PatchException("Could not find setAnimation method") | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../kotlin/app/revanced/patches/youtube/utils/lottie/fingerprints/SetAnimationFingerprint.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,24 @@ | ||
package app.revanced.patches.youtube.utils.lottie.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import app.revanced.patches.youtube.utils.lottie.fingerprints.SetAnimationFingerprint.LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object SetAnimationFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, | ||
parameters = listOf("I"), | ||
opcodes = listOf( | ||
Opcode.IF_EQZ, | ||
Opcode.NEW_INSTANCE, | ||
Opcode.NEW_INSTANCE, | ||
), | ||
customFingerprint = { methodDef, _ -> | ||
methodDef.definingClass == LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR | ||
} | ||
) { | ||
const val LOTTIE_ANIMATION_VIEW_CLASS_DESCRIPTOR = | ||
"Lcom/airbnb/lottie/LottieAnimationView;" | ||
} |
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
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
Oops, something went wrong.