Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(youtube/hide-seekbar): more fine grained hiding of seekbar #2252

Merged
merged 11 commits into from
May 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
import app.revanced.patches.youtube.layout.hide.seekbar.annotations.HideSeekbarCompatibility
import app.revanced.patches.youtube.layout.seekbar.bytecode.patch.SeekbarColorBytecodePatch
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch

Expand All @@ -34,12 +35,18 @@ class HideSeekbarPatch : BytecodePatch(
listOf(SeekbarFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SeekbarColorResourcePatch.addSeekbarPreferences(
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
SwitchPreference(
"revanced_hide_seekbar",
StringResource("revanced_hide_seekbar_title", "Hide seekbar"),
StringResource("revanced_hide_seekbar_summary_on", "Seekbar is hidden"),
StringResource("revanced_hide_seekbar_summary_off", "Seekbar is shown")
StringResource("revanced_hide_seekbar_title", "Hide seekbar in video player"),
StringResource("revanced_hide_seekbar_summary_on", "Video player seekbar is hidden"),
StringResource("revanced_hide_seekbar_summary_off", "Video player seekbar is shown")
),
SwitchPreference(
"revanced_hide_seekbar_thumbnail",
StringResource("revanced_hide_seekbar_thumbnail_title", "Hide seekbar in video thumbnails"),
StringResource("revanced_hide_seekbar_thumbnail_summary_on", "Thumbnail seekbar is hidden"),
StringResource("revanced_hide_seekbar_thumbnail_summary_off", "Thumbnail seekbar is shown")
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patches.youtube.layout.seekbar.annotations.SeekbarColorCompatibility
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.CreateDarkThemeSeekbarFingerprint
import app.revanced.patches.youtube.layout.seekbar.bytecode.fingerprints.SetSeekbarClickedColorFingerprint
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch
import app.revanced.patches.youtube.layout.theme.bytecode.patch.LithoColorHookPatch.Companion.lithoColorOverrideHook
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch
import app.revanced.util.patch.indexOfFirstConstantInstruction
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
Expand All @@ -37,7 +37,7 @@ class SeekbarColorBytecodePatch : BytecodePatch(
addInstructions(
registerIndex + 1,
"""
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I
move-result v$colorRegister
"""
)
Expand All @@ -47,7 +47,7 @@ class SeekbarColorBytecodePatch : BytecodePatch(
addInstructions(
registerIndex + 1,
"""
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorValue(I)I
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarColor(I)I
move-result v$colorRegister
"""
)
Expand All @@ -66,15 +66,15 @@ class SeekbarColorBytecodePatch : BytecodePatch(
addInstructions(
0,
"""
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getSeekbarColorOverride(I)I
invoke-static { v$colorRegister }, $INTEGRATIONS_CLASS_DESCRIPTOR->getVideoPlayerSeekbarClickedColor(I)I
move-result v$colorRegister
"""
)
}
}
} ?: return SetSeekbarClickedColorFingerprint.toErrorResult()

lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getSeekbarColorOverride")
lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getLithoColor")

return PatchResultSuccess()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.*
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
import app.revanced.patches.shared.settings.preference.BasePreference
import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import org.w3c.dom.Element
import java.io.Closeable

@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
class SeekbarColorResourcePatch : ResourcePatch {
class SeekbarColorResourcePatch : ResourcePatch, Closeable {
override fun execute(context: ResourceContext): PatchResult {
// Edit theme colors via bytecode.
// For that the resource id is used in a bytecode patch to change the color.
Expand Down Expand Up @@ -38,8 +42,24 @@ class SeekbarColorResourcePatch : ResourcePatch {
return PatchResultSuccess()
}

override fun close() {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
PreferenceScreen(
"revanced_seekbar_preference_screen",
StringResource("revanced_seekbar_preference_screen_title", "Seekbar settings"),
seekbarPreferences
)
)
}

companion object {
internal var inlineTimeBarColorizedBarPlayedColorDarkId = -1L
internal var inlineTimeBarPlayedNotHighlightedColorId = -1L

private val seekbarPreferences = mutableListOf<BasePreference>()

internal fun addSeekbarPreferences(vararg preferencesToAdd: BasePreference) {
seekbarPreferences.addAll(preferencesToAdd)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
import app.revanced.patches.shared.settings.preference.impl.InputType
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.preference.impl.TextPreference
import app.revanced.patches.youtube.layout.seekbar.resource.SeekbarColorResourcePatch
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.darkThemeBackgroundColor
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.lightThemeBackgroundColor
import app.revanced.patches.youtube.layout.theme.bytecode.patch.ThemeBytecodePatch.Companion.splashScreenBackgroundColor
Expand All @@ -18,16 +19,13 @@ import org.w3c.dom.Element
@DependsOn([SettingsPatch::class, ResourceMappingPatch::class])
class ThemeResourcePatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
SettingsPatch.PreferenceScreen.LAYOUT.addPreferences(
SeekbarColorResourcePatch.addSeekbarPreferences(
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
TextPreference(
"revanced_seekbar_color",
StringResource("revanced_seekbar_color_title", "Seekbar color"),
StringResource(
"revanced_seekbar_color_summary",
"The color of the seekbar"
),
StringResource("revanced_seekbar_color_summary", "The color of the seekbar"),
InputType.TEXT_CAP_CHARACTERS
),
)
)

// Edit theme colors via resources.
Expand Down