mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 05:37:40 +02:00
refactor(custom-seekbar-color): custom seekbar color now applied in light mode as well as dark mode
This commit is contained in:
@ -0,0 +1,15 @@
|
|||||||
|
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
|
|
||||||
|
object SeekbarColorFingerprint : MethodFingerprint(
|
||||||
|
customFingerprint = { methodDef ->
|
||||||
|
methodDef.implementation?.instructions?.any {
|
||||||
|
it.opcode.ordinal == Opcode.CONST.ordinal &&
|
||||||
|
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId
|
||||||
|
} == true
|
||||||
|
}
|
||||||
|
)
|
@ -1,96 +1,86 @@
|
|||||||
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.patch
|
package app.revanced.patches.youtube.layout.seekbar.seekbarcolor.patch
|
||||||
|
|
||||||
import app.revanced.extensions.findMutableMethodOf
|
import app.revanced.extensions.toErrorResult
|
||||||
import app.revanced.patcher.annotation.Description
|
import app.revanced.patcher.annotation.Description
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.annotation.Version
|
import app.revanced.patcher.annotation.Version
|
||||||
import app.revanced.patcher.data.BytecodeContext
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
import app.revanced.patcher.extensions.addInstructions
|
import app.revanced.patcher.extensions.addInstructions
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultError
|
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||||
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
|
import app.revanced.patches.shared.fingerprints.ControlsOverlayStyleFingerprint
|
||||||
|
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.fingerprints.SeekbarColorFingerprint
|
||||||
|
import app.revanced.patches.youtube.misc.resourceid.patch.SharedResourceIdPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||||
import app.revanced.util.integrations.Constants.SEEKBAR
|
import app.revanced.util.integrations.Constants.SEEKBAR
|
||||||
import org.jf.dexlib2.Opcode
|
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
|
import org.jf.dexlib2.iface.instruction.WideLiteralInstruction
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("custom-seekbar-color")
|
@Name("custom-seekbar-color")
|
||||||
@Description("Change seekbar color in dark mode.")
|
@Description("Change seekbar color.")
|
||||||
@DependsOn(
|
@DependsOn(
|
||||||
[
|
[
|
||||||
ResourceMappingPatch::class,
|
SettingsPatch::class,
|
||||||
SettingsPatch::class
|
SharedResourceIdPatch::class
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@YouTubeCompatibility
|
@YouTubeCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class SeekbarColorPatch : BytecodePatch() {
|
class SeekbarColorPatch : BytecodePatch(
|
||||||
|
listOf(
|
||||||
// list of resource names to get the id of
|
ControlsOverlayStyleFingerprint,
|
||||||
private val resourceIds = arrayOf(
|
SeekbarColorFingerprint
|
||||||
"inline_time_bar_colorized_bar_played_color_dark"
|
)
|
||||||
).map { name ->
|
) {
|
||||||
ResourceMappingPatch.resourceMappings.single { it.name == name }.id
|
|
||||||
}
|
|
||||||
private var patchSuccessArray = Array(resourceIds.size) {false}
|
|
||||||
|
|
||||||
override fun execute(context: BytecodeContext): PatchResult {
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
context.classes.forEach { classDef ->
|
SeekbarColorFingerprint.result?.mutableMethod?.let { method ->
|
||||||
classDef.methods.forEach { method ->
|
with (method.implementation!!.instructions) {
|
||||||
with(method.implementation) {
|
val insertIndex = this.indexOfFirst {
|
||||||
this?.instructions?.forEachIndexed { index, instruction ->
|
(it as? WideLiteralInstruction)?.wideLiteral == SharedResourceIdPatch.timeBarPlayedDarkLabelId
|
||||||
when (instruction.opcode) {
|
} + 2
|
||||||
Opcode.CONST -> {
|
|
||||||
when ((instruction as Instruction31i).wideLiteral) {
|
|
||||||
resourceIds[0] -> { // seekbar color
|
|
||||||
val registerIndex = index + 2
|
|
||||||
|
|
||||||
val mutableMethod = context.proxy(classDef).mutableClass.findMutableMethodOf(method)
|
val insertRegister = (elementAt(insertIndex) as OneRegisterInstruction).registerA
|
||||||
|
|
||||||
val viewRegister = (instructions.elementAt(registerIndex) as OneRegisterInstruction).registerA
|
method.addInstructions(
|
||||||
|
insertIndex + 1, """
|
||||||
mutableMethod.addInstructions(
|
invoke-static {v$insertRegister}, $SEEKBAR->enableCustomSeekbarColorDarkMode(I)I
|
||||||
registerIndex + 1, """
|
move-result v$insertRegister
|
||||||
invoke-static {v$viewRegister}, $SEEKBAR->enableCustomSeekbarColor(I)I
|
"""
|
||||||
move-result v$viewRegister
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
patchSuccessArray[0] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> return@forEachIndexed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val errorIndex: Int = patchSuccessArray.indexOf(false)
|
|
||||||
|
|
||||||
if (errorIndex == -1) {
|
|
||||||
/*
|
|
||||||
* Add settings
|
|
||||||
*/
|
|
||||||
SettingsPatch.addPreference(
|
|
||||||
arrayOf(
|
|
||||||
"PREFERENCE: SEEKBAR_SETTINGS",
|
|
||||||
"SETTINGS: CUSTOM_SEEKBAR_COLOR"
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
} ?: return SeekbarColorFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
val controlsOverlayStyleClassDef = ControlsOverlayStyleFingerprint.result?.classDef?: return ControlsOverlayStyleFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
val progressColorFingerprint =
|
||||||
|
object : MethodFingerprint(returnType = "V", parameters = listOf("I"), customFingerprint = { it.name == "e" }) {}
|
||||||
|
progressColorFingerprint.resolve(context, controlsOverlayStyleClassDef)
|
||||||
|
progressColorFingerprint.result?.mutableMethod?.addInstructions(
|
||||||
|
0, """
|
||||||
|
invoke-static {p1}, $SEEKBAR->enableCustomSeekbarColor(I)I
|
||||||
|
move-result p1
|
||||||
|
"""
|
||||||
|
)?: return progressColorFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add settings
|
||||||
|
*/
|
||||||
|
SettingsPatch.addPreference(
|
||||||
|
arrayOf(
|
||||||
|
"PREFERENCE: SEEKBAR_SETTINGS",
|
||||||
|
"SETTINGS: CUSTOM_SEEKBAR_COLOR"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
SettingsPatch.updatePatchStatus("custom-seekbar-color")
|
SettingsPatch.updatePatchStatus("custom-seekbar-color")
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
} else
|
|
||||||
return PatchResultError("Instruction not found: $errorIndex")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ class SharedResourceIdPatch : ResourcePatch {
|
|||||||
var relatedChipCloudMarginLabelId: Long = -1
|
var relatedChipCloudMarginLabelId: Long = -1
|
||||||
var rightCommentLabelId: Long = -1
|
var rightCommentLabelId: Long = -1
|
||||||
var scrubbingLabelId: Long = -1
|
var scrubbingLabelId: Long = -1
|
||||||
|
var timeBarPlayedDarkLabelId: Long = -1
|
||||||
var timeStampsContainerLabelId: Long = -1
|
var timeStampsContainerLabelId: Long = -1
|
||||||
var tooltipLabelId: Long = -1
|
var tooltipLabelId: Long = -1
|
||||||
var videoQualityFragmentLabelId: Long = -1
|
var videoQualityFragmentLabelId: Long = -1
|
||||||
@ -89,6 +90,7 @@ class SharedResourceIdPatch : ResourcePatch {
|
|||||||
relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
|
relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
|
||||||
rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c")
|
rightCommentLabelId = find(DRAWABLE, "ic_right_comment_32c")
|
||||||
scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
|
scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
|
||||||
|
timeBarPlayedDarkLabelId = find(COLOR, "inline_time_bar_colorized_bar_played_color_dark")
|
||||||
timeStampsContainerLabelId = find(ID, "timestamps_container")
|
timeStampsContainerLabelId = find(ID, "timestamps_container")
|
||||||
tooltipLabelId = find(LAYOUT, "tooltip_content_view")
|
tooltipLabelId = find(LAYOUT, "tooltip_content_view")
|
||||||
videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
|
videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
|
||||||
|
@ -93,7 +93,7 @@ Is it ready to submit?"</string>
|
|||||||
<string name="revanced_bypass_ambient_mode_restrictions_title">Bypass ambient mode restrictions</string>
|
<string name="revanced_bypass_ambient_mode_restrictions_title">Bypass ambient mode restrictions</string>
|
||||||
<string name="revanced_comments_title">Comments</string>
|
<string name="revanced_comments_title">Comments</string>
|
||||||
<string name="revanced_copytimestamp_success">Time Stamp copied to clipboard</string>
|
<string name="revanced_copytimestamp_success">Time Stamp copied to clipboard</string>
|
||||||
<string name="revanced_custom_seekbar_color_value_summary">Type the hex code of the seekbar color to use in dark mode</string>
|
<string name="revanced_custom_seekbar_color_value_summary">Type the hex code of the seekbar color</string>
|
||||||
<string name="revanced_custom_seekbar_color_value_title">Custom seekbar color value</string>
|
<string name="revanced_custom_seekbar_color_value_title">Custom seekbar color value</string>
|
||||||
<string name="revanced_default_video_quality_mobile_title">Default video quality Cellular</string>
|
<string name="revanced_default_video_quality_mobile_title">Default video quality Cellular</string>
|
||||||
<string name="revanced_default_video_quality_wifi_title">Default video quality Wi-Fi</string>
|
<string name="revanced_default_video_quality_wifi_title">Default video quality Wi-Fi</string>
|
||||||
@ -127,7 +127,7 @@ Is it ready to submit?"</string>
|
|||||||
<string name="revanced_enable_always_auto_repeat_title">Always auto repeat</string>
|
<string name="revanced_enable_always_auto_repeat_title">Always auto repeat</string>
|
||||||
<string name="revanced_enable_custom_seekbar_color_summary_off">Custom seekbar color is disabled</string>
|
<string name="revanced_enable_custom_seekbar_color_summary_off">Custom seekbar color is disabled</string>
|
||||||
<string name="revanced_enable_custom_seekbar_color_summary_on">Custom seekbar color is enabled</string>
|
<string name="revanced_enable_custom_seekbar_color_summary_on">Custom seekbar color is enabled</string>
|
||||||
<string name="revanced_enable_custom_seekbar_color_title">Enable custom seekbar color in dark mode</string>
|
<string name="revanced_enable_custom_seekbar_color_title">Enable custom seekbar color</string>
|
||||||
<string name="revanced_enable_custom_video_speed_summary_off">Custom video speed is disabled</string>
|
<string name="revanced_enable_custom_video_speed_summary_off">Custom video speed is disabled</string>
|
||||||
<string name="revanced_enable_custom_video_speed_summary_on">Custom video speed is enabled</string>
|
<string name="revanced_enable_custom_video_speed_summary_on">Custom video speed is enabled</string>
|
||||||
<string name="revanced_enable_custom_video_speed_title">Enable custom video speed</string>
|
<string name="revanced_enable_custom_video_speed_title">Enable custom video speed</string>
|
||||||
|
Reference in New Issue
Block a user