mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 05:07:41 +02:00
feat(youtube/patch-options): all patch options are now moved to the appropriate patch
This commit is contained in:
@ -5,25 +5,17 @@ import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.patches.shared.patch.options.PatchOptions
|
||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||
import app.revanced.util.resources.ResourceHelper.updatePatchStatusLabel
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@Patch
|
||||
@Name("custom-branding-name")
|
||||
@DependsOn(
|
||||
[
|
||||
PatchOptions::class,
|
||||
SettingsPatch::class
|
||||
]
|
||||
)
|
||||
@DependsOn([SettingsPatch::class])
|
||||
@Description("Changes the YouTube launcher name to your choice (defaults to ReVanced Extended).")
|
||||
@YouTubeCompatibility
|
||||
@Version("0.0.1")
|
||||
@ -32,7 +24,7 @@ class CustomBrandingNamePatch : ResourcePatch {
|
||||
|
||||
// App name
|
||||
val resourceFileNames = arrayOf("strings.xml")
|
||||
val appName = PatchOptions.YouTubeAppName
|
||||
val appName = YouTubeAppName
|
||||
|
||||
context.forEach {
|
||||
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
|
||||
@ -58,4 +50,14 @@ class CustomBrandingNamePatch : ResourcePatch {
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
companion object : OptionsContainer() {
|
||||
var YouTubeAppName: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "YouTubeAppName",
|
||||
default = "ReVanced Extended",
|
||||
title = "Application Name of YouTube",
|
||||
description = "The name of the YouTube it will show on your home screen."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,27 @@ import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultError
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.OptionsContainer
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.patches.shared.patch.options.PatchOptions
|
||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||
import app.revanced.util.resources.ResourceHelper.addEntryValues
|
||||
import app.revanced.util.resources.ResourceUtils
|
||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||
import app.revanced.util.resources.ResourceUtils.copyXmlNode
|
||||
|
||||
@Patch
|
||||
@Name("custom-double-tap-length")
|
||||
@Description("Add 'double-tap to seek' value.")
|
||||
@DependsOn(
|
||||
[
|
||||
PatchOptions::class,
|
||||
SettingsPatch::class
|
||||
]
|
||||
)
|
||||
@DependsOn([SettingsPatch::class])
|
||||
@YouTubeCompatibility
|
||||
@Version("0.0.1")
|
||||
class DoubleTapLengthPatch : ResourcePatch {
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
val arrayPath = "res/values-v21/arrays.xml"
|
||||
val entriesName = "double_tap_length_entries"
|
||||
val entryValueName = "double_tap_length_values"
|
||||
|
||||
/**
|
||||
* Copy arrays
|
||||
@ -43,15 +37,15 @@ class DoubleTapLengthPatch : ResourcePatch {
|
||||
)
|
||||
)
|
||||
|
||||
val speed = PatchOptions.CustomDoubleTapLengthArrays
|
||||
val length = DoubleTapLengthArrays
|
||||
?: return PatchResultError("Invalid double-tap length array.")
|
||||
|
||||
val splits = speed.replace(" ","").split(",")
|
||||
if (splits.isEmpty()) throw IllegalArgumentException("Invalid speed elements")
|
||||
val speedElements = splits.map { it }
|
||||
val splits = length.replace(" ","").split(",")
|
||||
if (splits.isEmpty()) throw IllegalArgumentException("Invalid double-tap length elements")
|
||||
val lengthElements = splits.map { it }
|
||||
for (index in 0 until splits.count()) {
|
||||
context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRY_VALUE_NAME)
|
||||
context.addEntryValues(TARGET_ARRAY_PATH, speedElements[index], TARGET_ENTRIES_NAME)
|
||||
context.addEntryValues(arrayPath, lengthElements[index], entryValueName)
|
||||
context.addEntryValues(arrayPath, lengthElements[index], entriesName)
|
||||
}
|
||||
|
||||
SettingsPatch.updatePatchStatus("custom-double-tap-length")
|
||||
@ -59,9 +53,14 @@ class DoubleTapLengthPatch : ResourcePatch {
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val TARGET_ARRAY_PATH = "res/values-v21/arrays.xml"
|
||||
private const val TARGET_ENTRIES_NAME = "double_tap_length_entries"
|
||||
private const val TARGET_ENTRY_VALUE_NAME = "double_tap_length_values"
|
||||
companion object : OptionsContainer() {
|
||||
var DoubleTapLengthArrays: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "DoubleTapLengthArrays",
|
||||
default = "3, 5, 10, 15, 20, 30, 60, 120, 180",
|
||||
title = "Double-tap to seek Values",
|
||||
description = "A list of custom double-tap to seek lengths. Be sure to separate them with commas (,)."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
@ -4,13 +4,10 @@ import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.patches.shared.patch.options.PatchOptions
|
||||
import app.revanced.patches.youtube.layout.etc.theme.patch.GeneralThemePatch.Companion.isMonetPatchIncluded
|
||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||
import app.revanced.util.resources.ResourceHelper.updatePatchStatusTheme
|
||||
@ -22,7 +19,6 @@ import org.w3c.dom.Element
|
||||
@DependsOn(
|
||||
[
|
||||
GeneralThemePatch::class,
|
||||
PatchOptions::class,
|
||||
SettingsPatch::class
|
||||
]
|
||||
)
|
||||
@ -31,9 +27,7 @@ import org.w3c.dom.Element
|
||||
class ThemePatch : ResourcePatch {
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
|
||||
arrayOf("values", "values-v31").forEach {
|
||||
context.setTheme(it)
|
||||
}
|
||||
arrayOf("values", "values-v31").forEach { context.setTheme(it) }
|
||||
|
||||
val currentTheme = if (isMonetPatchIncluded) "mix" else "amoled"
|
||||
|
||||
@ -41,22 +35,32 @@ class ThemePatch : ResourcePatch {
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
private companion object {
|
||||
private fun ResourceContext.setTheme(valuesPath: String) {
|
||||
this.xmlEditor["res/$valuesPath/colors.xml"].use { editor ->
|
||||
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
for (i in 0 until resourcesNode.childNodes.length) {
|
||||
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
||||
private fun ResourceContext.setTheme(valuesPath: String) {
|
||||
this.xmlEditor["res/$valuesPath/colors.xml"].use { editor ->
|
||||
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
|
||||
|
||||
node.textContent = when (node.getAttribute("name")) {
|
||||
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3",
|
||||
"yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> PatchOptions.darkThemeBackgroundColor!!
|
||||
for (i in 0 until resourcesNode.childNodes.length) {
|
||||
val node = resourcesNode.childNodes.item(i) as? Element ?: continue
|
||||
|
||||
else -> continue
|
||||
}
|
||||
node.textContent = when (node.getAttribute("name")) {
|
||||
"yt_black0", "yt_black1", "yt_black1_opacity95", "yt_black1_opacity98", "yt_black2", "yt_black3",
|
||||
"yt_black4", "yt_status_bar_background_dark", "material_grey_850" -> darkThemeBackgroundColor
|
||||
|
||||
else -> continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object : OptionsContainer() {
|
||||
var darkThemeBackgroundColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "darkThemeBackgroundColor",
|
||||
default = "@android:color/black",
|
||||
title = "Background color for the dark theme",
|
||||
description = "The background color of the dark theme. Can be a hex color or a resource reference."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,10 @@ import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.*
|
||||
import app.revanced.patcher.patch.annotations.DependsOn
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patches.shared.annotation.YouTubeCompatibility
|
||||
import app.revanced.patches.shared.patch.options.PatchOptions
|
||||
import app.revanced.patches.youtube.layout.seekbar.seekbarcolor.bytecode.patch.SeekbarColorBytecodePatch
|
||||
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
|
||||
import org.w3c.dom.Element
|
||||
@ -21,7 +18,6 @@ import org.w3c.dom.Element
|
||||
@Description("Change seekbar color and progressbar color.")
|
||||
@DependsOn(
|
||||
[
|
||||
PatchOptions::class,
|
||||
SeekbarColorBytecodePatch::class,
|
||||
SettingsPatch::class
|
||||
]
|
||||
@ -31,14 +27,14 @@ import org.w3c.dom.Element
|
||||
class ThemePatch : ResourcePatch {
|
||||
override fun execute(context: ResourceContext): PatchResult {
|
||||
|
||||
context.xmlEditor[RESOURCE_FILE_PATH].use {
|
||||
context.xmlEditor["res/drawable/resume_playback_progressbar_drawable.xml"].use {
|
||||
it.file.doRecursively {
|
||||
arrayOf("color").forEach replacement@{ replacement ->
|
||||
if (it !is Element) return@replacement
|
||||
|
||||
it.getAttributeNode("android:$replacement")?.let { attribute ->
|
||||
if (attribute.textContent.startsWith("@color/"))
|
||||
attribute.textContent = PatchOptions.resumedProgressBarColor!!
|
||||
attribute.textContent = resumedProgressBarColor
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,7 +54,15 @@ class ThemePatch : ResourcePatch {
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
private companion object {
|
||||
const val RESOURCE_FILE_PATH = "res/drawable/resume_playback_progressbar_drawable.xml"
|
||||
|
||||
companion object : OptionsContainer() {
|
||||
var resumedProgressBarColor: String? by option(
|
||||
PatchOption.StringOption(
|
||||
key = "resumedProgressBarColor",
|
||||
default = "#ffff0000",
|
||||
title = "Resumed progressbar color",
|
||||
description = "Resumed progressbar color in playlists and history. Can be a hex color or a resource reference."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user