Skip to content

Commit

Permalink
feat(youtube/hide-seekbar): more fine grained hiding of seekbar (#2252)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <[email protected]>
  • Loading branch information
LisoUseInAIKyrios and oSumAtrIX authored May 27, 2023
1 parent 94f31f8 commit 0f07bf4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ 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

@Patch
@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.")
Expand All @@ -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")
)
)

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
@@ -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<BasePreference>()

internal fun addPreferences(vararg preferencesToAdd: BasePreference) {
seekbarPreferences.addAll(preferencesToAdd)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0f07bf4

Please sign in to comment.