Skip to content

Commit

Permalink
feat(YouTube/Toolbar components): add Hide YouTube Doodles setting
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Oct 6, 2024
1 parent a4227ae commit c023138
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import app.revanced.patches.youtube.general.toolbar.fingerprints.SearchBarParent
import app.revanced.patches.youtube.general.toolbar.fingerprints.SearchResultFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.SetActionBarRingoFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.SetWordMarkHeaderFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.YoodlesImageViewFingerprint
import app.revanced.patches.youtube.general.toolbar.fingerprints.YouActionBarFingerprint
import app.revanced.patches.youtube.utils.castbutton.CastButtonPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
Expand All @@ -42,6 +43,7 @@ import app.revanced.util.REGISTER_TEMPLATE_REPLACEMENT
import app.revanced.util.alsoResolve
import app.revanced.util.doRecursively
import app.revanced.util.findMethodOrThrow
import app.revanced.util.findOpcodeIndicesReversed
import app.revanced.util.getReference
import app.revanced.util.getWalkerMethod
import app.revanced.util.indexOfFirstInstructionOrThrow
Expand Down Expand Up @@ -84,6 +86,7 @@ object ToolBarComponentsPatch : BaseBytecodePatch(
SetActionBarRingoFingerprint,
SetWordMarkHeaderFingerprint,
ImageSearchButtonConfigFingerprint,
YoodlesImageViewFingerprint,
)
) {
private const val TARGET_RESOURCE_PATH = "res/layout/action_bar_ringo_background.xml"
Expand Down Expand Up @@ -366,6 +369,26 @@ object ToolBarComponentsPatch : BaseBytecodePatch(

// endregion

// region patch for hide YouTube Doodles

YoodlesImageViewFingerprint.resultOrThrow().mutableMethod.apply {
findOpcodeIndicesReversed{
opcode == Opcode.INVOKE_VIRTUAL
&& getReference<MethodReference>()?.name == "setImageDrawable"
}.forEach { insertIndex ->
val (viewRegister, drawableRegister) = getInstruction<FiveRegisterInstruction>(insertIndex).let {
Pair(it.registerC, it.registerD)
}
replaceInstruction(
insertIndex,
"invoke-static {v$viewRegister, v$drawableRegister}, " +
"$GENERAL_CLASS_DESCRIPTOR->hideYouTubeDoodles(Landroid/widget/ImageView;Landroid/graphics/drawable/Drawable;)V"
)
}
}

// endregion

// region patch for replace create button

CreateButtonDrawableFingerprint.resultOrThrow().mutableMethod.apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.revanced.patches.youtube.general.toolbar.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.YouTubeLogo
import app.revanced.util.fingerprint.LiteralValueFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

@Suppress("SpellCheckingInspection")
internal object YoodlesImageViewFingerprint : LiteralValueFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
parameters = listOf("L", "L"),
returnType = "Landroid/view/View;",
literalSupplier = { YouTubeLogo }
)
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ object SharedResourceIdPatch : ResourcePatch() {
var VideoZoomSnapIndicator = -1L
var VoiceSearch = -1L
var YouTubeControlsOverlaySubtitleButton = -1L
var YouTubeLogo = -1L
var YtOutlinePictureInPictureWhite = -1L
var YtOutlineVideoCamera = -1L
var YtOutlineXWhite = -1L
Expand Down Expand Up @@ -233,6 +234,7 @@ object SharedResourceIdPatch : ResourcePatch() {
VoiceSearch = getId(ID, "voice_search")
YouTubeControlsOverlaySubtitleButton =
getId(LAYOUT, "youtube_controls_overlay_subtitle_button")
YouTubeLogo = getId(ID, "youtube_logo")
YtOutlinePictureInPictureWhite = getId(DRAWABLE, "yt_outline_picture_in_picture_white_24")
YtOutlineVideoCamera = getId(DRAWABLE, "yt_outline_video_camera_black_24")
YtOutlineXWhite = getId(DRAWABLE, "yt_outline_x_white_24")
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/youtube/settings/host/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,13 @@ You tab → View channel → Menu → Settings"</string>
<string name="revanced_hide_voice_search_button_title">Hide voice search button</string>
<string name="revanced_hide_voice_search_button_summary_on">Voice search button is hidden.</string>
<string name="revanced_hide_voice_search_button_summary_off">Voice search button is shown.</string>
<string name="revanced_hide_youtube_doodles_title">Hide YouTube Doodles</string>
<string name="revanced_hide_youtube_doodles_summary_on">YouTube Doodles are hidden.</string>
<string name="revanced_hide_youtube_doodles_summary_off">YouTube Doodles are shown.</string>
<string name="revanced_hide_youtube_doodles_user_dialog_message">"YouTube Doodles show up a few days each year.

If a YouTube Doodle is currently showing in your region and this hide setting is on, then the filter bar below the search bar will also be hidden."</string>

<string name="revanced_replace_toolbar_create_button_title">Replace Create button</string>
<string name="revanced_replace_toolbar_create_button_summary">Replaces the Create button with the Settings button.</string>
<string name="revanced_replace_toolbar_create_button_type_title">Action type to assign to button</string>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/youtube/settings/xml/revanced_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@

<!-- SETTINGS: TOOLBAR_COMPONENTS
<SwitchPreference android:title="@string/revanced_hide_voice_search_button_title" android:key="revanced_hide_voice_search_button" android:summaryOn="@string/revanced_hide_voice_search_button_summary_on" android:summaryOff="@string/revanced_hide_voice_search_button_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_youtube_doodles_title" android:key="revanced_hide_youtube_doodles" android:summaryOn="@string/revanced_hide_youtube_doodles_summary_on" android:summaryOff="@string/revanced_hide_youtube_doodles_summary_off" />
<PreferenceCategory android:title="@string/revanced_preference_category_experimental_flag" android:layout="@layout/revanced_settings_preferences_category"/>
<SwitchPreference android:title="@string/revanced_replace_toolbar_create_button_title" android:key="revanced_replace_toolbar_create_button" android:summary="@string/revanced_replace_toolbar_create_button_summary" />
<SwitchPreference android:title="@string/revanced_replace_toolbar_create_button_type_title" android:key="revanced_replace_toolbar_create_button_type" android:summaryOn="@string/revanced_replace_toolbar_create_button_type_summary_on" android:summaryOff="@string/revanced_replace_toolbar_create_button_type_summary_off" android:dependency="revanced_replace_toolbar_create_button" />SETTINGS: TOOLBAR_COMPONENTS -->
Expand Down

0 comments on commit c023138

Please sign in to comment.