Skip to content

Commit

Permalink
feat(YouTube - Shorts components): Add Double-tap animation settings
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and Francesco146 committed Jun 29, 2024
1 parent 234feb7 commit a1868ec
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 68 deletions.

This file was deleted.

This file was deleted.

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"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ object ShortsComponentPatch : BaseBytecodePatch(
PlayerTypeHookPatch::class,
SettingsPatch::class,
SharedResourceIdPatch::class,
ShortsAnimationPatch::class,
ShortsNavigationBarPatch::class,
ShortsToolBarPatch::class,
VideoInformationPatch::class
Expand Down
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)
},
)
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")
}
}
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;"
}
16 changes: 16 additions & 0 deletions src/main/resources/youtube/settings/host/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@
<item>PHONE</item>
<item>TABLET</item>
</string-array>
<string-array name="revanced_shorts_double_tap_to_like_animation_entries">
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_1</item>
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_2</item>
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_3</item>
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_4</item>
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_5</item>
<item>@string/revanced_shorts_double_tap_to_like_animation_entry_6</item>
</string-array>
<string-array name="revanced_shorts_double_tap_to_like_animation_entry_values">
<item>ORIGINAL</item>
<item>THUMBS_UP</item>
<item>THUMBS_UP_CAIRO</item>
<item>HEART</item>
<item>HEART_TINT</item>
<item>HIDDEN</item>
</string-array>
<string-array name="revanced_spoof_client_general_options_entries">
<item>@string/revanced_spoof_client_options_entry_ios</item>
<item>@string/revanced_spoof_client_options_entry_android_testsuite</item>
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@
<SwitchPreference android:title="@string/revanced_hide_shorts_remix_button_title" android:key="revanced_hide_shorts_remix_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_remix_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_remix_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_sound_button_title" android:key="revanced_hide_shorts_sound_button" android:defaultValue="true" android:summaryOn="@string/revanced_hide_shorts_sound_button_summary_on" android:summaryOff="@string/revanced_hide_shorts_sound_button_summary_off" />
<PreferenceCategory android:title="@string/revanced_preference_category_animation_feedback" android:layout="@layout/revanced_settings_preferences_category"/>
<SwitchPreference android:title="@string/revanced_hide_shorts_play_pause_button_background_title" android:key="revanced_hide_shorts_play_pause_button_background" android:summaryOn="@string/revanced_hide_shorts_play_pause_button_background_summary_on" android:summaryOff="@string/revanced_hide_shorts_play_pause_button_background_summary_off" />
<ListPreference android:entries="@array/revanced_shorts_double_tap_to_like_animation_entries" android:title="@string/revanced_shorts_double_tap_to_like_animation_title" android:key="revanced_shorts_double_tap_to_like_animation" android:entryValues="@array/revanced_shorts_double_tap_to_like_animation_entry_values" />
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>
<SwitchPreference android:title="@string/revanced_hide_shorts_toolbar_title" android:key="revanced_hide_shorts_toolbar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_shorts_toolbar_summary_on" android:summaryOff="@string/revanced_hide_shorts_toolbar_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_shorts_navigation_bar_title" android:key="revanced_hide_shorts_navigation_bar" android:defaultValue="false" android:summaryOn="@string/revanced_hide_shorts_navigation_bar_summary_on" android:summaryOff="@string/revanced_hide_shorts_navigation_bar_summary_off" />
Expand Down Expand Up @@ -703,8 +707,6 @@
<PreferenceCategory android:title="@string/revanced_preference_category_others" android:layout="@layout/revanced_settings_preferences_category">
<Preference android:title="Custom double tap length" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="GmsCore support" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide animated button background" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide double tap to like animations" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Hide Shorts dimming" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
<Preference android:title="Icon" android:summary="@string/revanced_icon_default" android:selectable="false"/>
<Preference android:title="Label" android:summary="@string/revanced_label_default" android:selectable="false"/>
Expand Down
Loading

0 comments on commit a1868ec

Please sign in to comment.