feat(YouTube - Theme): Add option to use custom seekbar accent color (#4337)

This commit is contained in:
LisoUseInAIKyrios
2025-01-23 22:15:23 +02:00
committed by GitHub
parent e69197c6e5
commit 952b4fc4c9
6 changed files with 124 additions and 87 deletions

View File

@ -200,25 +200,27 @@ val seekbarColorPatch = bytecodePatch(
)
execute {
fun MutableMethod.addColorChangeInstructions(resourceId: Long) {
val registerIndex = indexOfFirstLiteralInstructionOrThrow(resourceId) + 2
val colorRegister = getInstruction<OneRegisterInstruction>(registerIndex).registerA
fun MutableMethod.addColorChangeInstructions(resourceId: Long, methodName: String) {
val index = indexOfFirstLiteralInstructionOrThrow(resourceId)
val insertIndex = indexOfFirstInstructionOrThrow(index, Opcode.MOVE_RESULT)
val register = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
registerIndex + 1,
insertIndex + 1,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$methodName(I)I
move-result v$register
"""
invoke-static { v$colorRegister }, $EXTENSION_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I
move-result v$colorRegister
""",
)
}
playerSeekbarColorFingerprint.method.apply {
addColorChangeInstructions(inlineTimeBarColorizedBarPlayedColorDarkId)
addColorChangeInstructions(inlineTimeBarPlayedNotHighlightedColorId)
addColorChangeInstructions(inlineTimeBarColorizedBarPlayedColorDarkId, "getVideoPlayerSeekbarColor")
addColorChangeInstructions(inlineTimeBarPlayedNotHighlightedColorId, "getVideoPlayerSeekbarColor")
}
shortsSeekbarColorFingerprint.method.apply {
addColorChangeInstructions(reelTimeBarPlayedColorId)
addColorChangeInstructions(reelTimeBarPlayedColorId, "getVideoPlayerSeekbarColor")
}
setSeekbarClickedColorFingerprint.originalMethod.let {
@ -245,17 +247,7 @@ val seekbarColorPatch = bytecodePatch(
// 19.25+ changes
playerSeekbarHandleColorFingerprint.method.apply {
val index = indexOfFirstLiteralInstructionOrThrow(ytStaticBrandRedId)
val insertIndex = indexOfFirstInstructionOrThrow(index, Opcode.MOVE_RESULT)
val register = getInstruction<OneRegisterInstruction>(insertIndex).registerA
addInstructions(
insertIndex + 1,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getSeekbarScrubHandleColor(I)I
move-result v$register
"""
)
addColorChangeInstructions(ytStaticBrandRedId, "getVideoPlayerSeekbarColor")
}
// If hiding feed seekbar thumbnails, then turn off the cairo gradient
@ -273,16 +265,19 @@ val seekbarColorPatch = bytecodePatch(
addInstructions(
index + 1,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->showWatchHistoryProgressDrawable(Z)Z
move-result v$register
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->showWatchHistoryProgressDrawable(Z)Z
move-result v$register
"""
)
}
}
lithoLinearGradientFingerprint.method.addInstruction(
lithoLinearGradientFingerprint.method.addInstructions(
0,
"invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->setLinearGradient([I[F)V"
"""
invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->getLithoLinearGradient([I[F)[I
move-result-object p4
"""
)
val playerFingerprint =
@ -302,7 +297,7 @@ val seekbarColorPatch = bytecodePatch(
addInstructions(
index + 1,
"""
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getLinearGradient([I)[I
invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getPlayerLinearGradient([I)[I
move-result-object v$register
"""
)

View File

@ -13,6 +13,8 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
import app.revanced.patches.shared.misc.settings.preference.TextPreference
import app.revanced.patches.youtube.layout.seekbar.seekbarColorPatch
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
import app.revanced.patches.youtube.misc.settings.settingsPatch
import app.revanced.util.forEachChildElement
@ -71,6 +73,7 @@ val themePatch = bytecodePatch(
dependsOn(
lithoColorHookPatch,
seekbarColorPatch,
versionCheckPatch,
resourcePatch {
dependsOn(
settingsPatch,
@ -83,9 +86,15 @@ val themePatch = bytecodePatch(
PreferenceScreen.SEEKBAR.addPreferences(
SwitchPreference("revanced_seekbar_custom_color"),
TextPreference("revanced_seekbar_custom_color_value", inputType = InputType.TEXT_CAP_CHARACTERS),
TextPreference("revanced_seekbar_custom_color_primary", inputType = InputType.TEXT_CAP_CHARACTERS),
)
if (is_19_25_or_greater) {
PreferenceScreen.SEEKBAR.addPreferences(
TextPreference("revanced_seekbar_custom_color_accent", inputType = InputType.TEXT_CAP_CHARACTERS),
)
}
// Edit theme colors via resources.
document("res/values/colors.xml").use { document ->

View File

@ -1223,8 +1223,10 @@ Swipe to expand or close"</string>
<string name="revanced_seekbar_custom_color_title">Enable custom seekbar color</string>
<string name="revanced_seekbar_custom_color_summary_on">Custom seekbar color is shown</string>
<string name="revanced_seekbar_custom_color_summary_off">Original seekbar color is shown</string>
<string name="revanced_seekbar_custom_color_value_title">Custom seekbar color</string>
<string name="revanced_seekbar_custom_color_value_summary">The color of the seekbar</string>
<string name="revanced_seekbar_custom_color_primary_title">Custom seekbar color</string>
<string name="revanced_seekbar_custom_color_primary_summary">The color of the seekbar</string>
<string name="revanced_seekbar_custom_color_accent_title">Custom seekbar accent color</string>
<string name="revanced_seekbar_custom_color_accent_summary">The accent color of the seekbar</string>
<string name="revanced_seekbar_custom_color_invalid">Invalid seekbar color value</string>
</patch>
<patch id="layout.thumbnails.bypassImageRegionRestrictionsPatch">