From 0f07bf467a4aa06c9bcdf60a2498d88eea8c1429 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 27 May 2023 11:52:03 +0400 Subject: [PATCH] feat(youtube/hide-seekbar): more fine grained hiding of seekbar (#2252) Co-authored-by: oSumAtrIX --- .../hide/seekbar/patch/HideSeekbarPatch.kt | 20 +++++++--- .../patch/SeekbarColorBytecodePatch.kt | 10 ++--- .../resource/SeekbarPreferencesPatch.kt | 39 +++++++++++++++++++ .../theme/resource/ThemeResourcePatch.kt | 12 +++--- 4 files changed, 64 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarPreferencesPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt index 08102a5c4..7a3fde5a5 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/patch/HideSeekbarPatch.kt @@ -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.SeekbarPreferencesPatch import app.revanced.patches.youtube.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @@ -24,7 +25,10 @@ import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch @DependsOn([ IntegrationsPatch::class, SettingsPatch::class, - SeekbarColorBytecodePatch::class // Used to hide the seekbar in the feed and watch history + // Does not alter the behavior of the seek bar by default. + SeekbarColorBytecodePatch::class, + // Used to add preferences to the seekbar settings menu. + SeekbarPreferencesPatch::class ]) @Name("hide-seekbar") @Description("Hides the seekbar.") @@ -34,12 +38,18 @@ class HideSeekbarPatch : BytecodePatch( listOf(SeekbarFingerprint) ) { override fun execute(context: BytecodeContext): PatchResult { - SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SeekbarPreferencesPatch.addPreferences( 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") ) ) diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt index 752f23afa..bf3d4cea3 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/bytecode/patch/SeekbarColorBytecodePatch.kt @@ -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 @@ -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 """ ) @@ -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 """ ) @@ -66,7 +66,7 @@ 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 """ ) @@ -74,7 +74,7 @@ class SeekbarColorBytecodePatch : BytecodePatch( } } ?: return SetSeekbarClickedColorFingerprint.toErrorResult() - lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getSeekbarColorOverride") + lithoColorOverrideHook(INTEGRATIONS_CLASS_DESCRIPTOR, "getLithoColor") return PatchResultSuccess() } diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarPreferencesPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarPreferencesPatch.kt new file mode 100644 index 000000000..17a3f168e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/resource/SeekbarPreferencesPatch.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.youtube.layout.seekbar.resource + +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 java.io.Closeable + +@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) +class SeekbarPreferencesPatch : ResourcePatch, Closeable { + override fun execute(context: ResourceContext): PatchResult { + + // Nothing to do here. All work is done in close method. + + 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 { + private val seekbarPreferences = mutableListOf() + + internal fun addPreferences(vararg preferencesToAdd: BasePreference) { + seekbarPreferences.addAll(preferencesToAdd) + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt index a69278309..83ca11e2f 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/layout/theme/resource/ThemeResourcePatch.kt @@ -9,25 +9,23 @@ 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.SeekbarPreferencesPatch 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 import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch import org.w3c.dom.Element -@DependsOn([SettingsPatch::class, ResourceMappingPatch::class]) +@DependsOn([SettingsPatch::class, ResourceMappingPatch::class, SeekbarPreferencesPatch::class]) class ThemeResourcePatch : ResourcePatch { override fun execute(context: ResourceContext): PatchResult { - SettingsPatch.PreferenceScreen.LAYOUT.addPreferences( + SeekbarPreferencesPatch.addPreferences( 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.