mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-05 00:54:32 +02:00
feat(YouTube/Premium heading): allow using default heading (selectable through options.json
)
This commit is contained in:
parent
c65aa00dc5
commit
d535ab3df7
@ -1,82 +0,0 @@
|
||||
package app.revanced.patches.youtube.layout.forceheader
|
||||
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.StandardCopyOption
|
||||
import kotlin.io.path.exists
|
||||
|
||||
@Patch(
|
||||
name = "Force premium heading",
|
||||
description = "Forces premium heading on the homepage.",
|
||||
dependencies = [SettingsPatch::class],
|
||||
compatiblePackages = [
|
||||
CompatiblePackage(
|
||||
"com.google.android.youtube",
|
||||
[
|
||||
"18.25.40",
|
||||
"18.27.36",
|
||||
"18.29.38",
|
||||
"18.30.37",
|
||||
"18.31.40",
|
||||
"18.32.39",
|
||||
"18.33.40",
|
||||
"18.34.38",
|
||||
"18.35.36",
|
||||
"18.36.39",
|
||||
"18.37.36",
|
||||
"18.38.44",
|
||||
"18.39.41",
|
||||
"18.40.34",
|
||||
"18.41.39"
|
||||
]
|
||||
)
|
||||
],
|
||||
use = false
|
||||
)
|
||||
@Suppress("unused")
|
||||
object PremiumHeadingPatch : ResourcePatch() {
|
||||
override fun execute(context: ResourceContext) {
|
||||
val resDirectory = context["res"]
|
||||
if (!resDirectory.isDirectory)
|
||||
throw PatchException("The res folder can not be found.")
|
||||
|
||||
val (original, replacement) = "yt_premium_wordmark_header" to "yt_wordmark_header"
|
||||
val modes = arrayOf("light", "dark")
|
||||
|
||||
arrayOf("xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi").forEach { size ->
|
||||
val headingDirectory = resDirectory.resolve("drawable-$size")
|
||||
modes.forEach { mode ->
|
||||
val fromPath = headingDirectory.resolve("${original}_$mode.png").toPath()
|
||||
val toPath = headingDirectory.resolve("${replacement}_$mode.png").toPath()
|
||||
|
||||
if (!fromPath.exists())
|
||||
throw PatchException("The file $fromPath does not exist in the resources. Therefore, this patch can not succeed.")
|
||||
Files.copy(
|
||||
fromPath,
|
||||
toPath,
|
||||
StandardCopyOption.REPLACE_EXISTING
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val prefs = context["res/xml/revanced_prefs.xml"]
|
||||
prefs.writeText(
|
||||
prefs.readText()
|
||||
.replace(
|
||||
"HEADER_SWITCH",
|
||||
"FORCE_PREMIUM_HEADER"
|
||||
).replace(
|
||||
"Header switch",
|
||||
"force-premium-heading"
|
||||
)
|
||||
)
|
||||
|
||||
SettingsPatch.updatePatchStatus("force-premium-heading")
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package app.revanced.patches.youtube.layout.header
|
||||
|
||||
import app.revanced.patcher.data.ResourceContext
|
||||
import app.revanced.patcher.patch.PatchException
|
||||
import app.revanced.patcher.patch.ResourcePatch
|
||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||
import app.revanced.patcher.patch.annotation.Patch
|
||||
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
|
||||
import app.revanced.patches.youtube.utils.settings.SettingsPatch
|
||||
import app.revanced.util.resources.ResourceHelper.updatePatchStatusHeader
|
||||
import kotlin.io.path.copyTo
|
||||
|
||||
@Patch(
|
||||
name = "Premium heading",
|
||||
description = "Show or hide the premium heading.",
|
||||
dependencies = [SettingsPatch::class],
|
||||
compatiblePackages = [
|
||||
CompatiblePackage(
|
||||
"com.google.android.youtube",
|
||||
[
|
||||
"18.25.40",
|
||||
"18.27.36",
|
||||
"18.29.38",
|
||||
"18.30.37",
|
||||
"18.31.40",
|
||||
"18.32.39",
|
||||
"18.33.40",
|
||||
"18.34.38",
|
||||
"18.35.36",
|
||||
"18.36.39",
|
||||
"18.37.36",
|
||||
"18.38.44",
|
||||
"18.39.41",
|
||||
"18.40.34",
|
||||
"18.41.39"
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
@Suppress("unused")
|
||||
object PremiumHeadingPatch : ResourcePatch() {
|
||||
private const val DEFAULT_HEADING_RES = "yt_wordmark_header"
|
||||
private const val PREMIUM_HEADING_RES = "yt_premium_wordmark_header"
|
||||
|
||||
private val UsePremiumHeading by booleanPatchOption(
|
||||
key = "UsePremiumHeading",
|
||||
default = true,
|
||||
title = "Use premium heading",
|
||||
description = "Whether to use the premium heading.",
|
||||
required = true,
|
||||
)
|
||||
|
||||
override fun execute(context: ResourceContext) {
|
||||
val resDirectory = context["res"]
|
||||
|
||||
val (original, replacement) = if (UsePremiumHeading == true)
|
||||
PREMIUM_HEADING_RES to DEFAULT_HEADING_RES
|
||||
else
|
||||
DEFAULT_HEADING_RES to PREMIUM_HEADING_RES
|
||||
|
||||
val variants = arrayOf("light", "dark")
|
||||
|
||||
arrayOf(
|
||||
"xxxhdpi",
|
||||
"xxhdpi",
|
||||
"xhdpi",
|
||||
"hdpi",
|
||||
"mdpi"
|
||||
).mapNotNull { dpi ->
|
||||
resDirectory.resolve("drawable-$dpi").takeIf { it.exists() }?.toPath()
|
||||
}.also {
|
||||
if (it.isEmpty())
|
||||
throw PatchException("The drawable folder can not be found. Therefore, the patch can not be applied.")
|
||||
}.forEach { path ->
|
||||
|
||||
variants.forEach { mode ->
|
||||
val fromPath = path.resolve("${original}_$mode.png")
|
||||
val toPath = path.resolve("${replacement}_$mode.png")
|
||||
|
||||
fromPath.copyTo(toPath, true)
|
||||
}
|
||||
}
|
||||
|
||||
val header = if (UsePremiumHeading == true)
|
||||
"Premium"
|
||||
else
|
||||
"Default"
|
||||
|
||||
context.updatePatchStatusHeader(header)
|
||||
}
|
||||
}
|
@ -84,7 +84,6 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
var TotalTime: Long = -1
|
||||
var VideoQualityBottomSheet: Long = -1
|
||||
var VideoZoomIndicatorLayout: Long = -1
|
||||
var WordMarkHeader: Long = -1
|
||||
var YoutubeControlsOverlay: Long = -1
|
||||
var YtOutlineArrowTimeBlack: Long = -1
|
||||
var YtOutlineFireBlack: Long = -1
|
||||
@ -168,7 +167,6 @@ object SharedResourceIdPatch : ResourcePatch() {
|
||||
TotalTime = find(STRING, "total_time")
|
||||
VideoQualityBottomSheet = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
|
||||
VideoZoomIndicatorLayout = find(ID, "video_zoom_indicator_layout")
|
||||
WordMarkHeader = find(ATTR, "ytWordmarkHeader")
|
||||
YoutubeControlsOverlay = find(ID, "youtube_controls_overlay")
|
||||
YtOutlineArrowTimeBlack = find(DRAWABLE, "yt_outline_arrow_time_black_24")
|
||||
YtOutlineFireBlack = find(DRAWABLE, "yt_outline_fire_black_24")
|
||||
|
@ -63,6 +63,7 @@
|
||||
<string name="revanced_hide_subscriptions_button_summary_on">@string/revanced_hide_shorts_player_subscriptions_button_summary_on</string>
|
||||
<string name="revanced_hide_subscriptions_button_title">@string/revanced_hide_shorts_player_subscriptions_button_title</string>
|
||||
|
||||
<string name="revanced_header_default">Stock</string>
|
||||
<string name="revanced_icons_default">Stock</string>
|
||||
<string name="revanced_icons_mmt">MMT</string>
|
||||
<string name="revanced_icons_revancify_blue">Revancify Blue</string>
|
||||
|
@ -436,6 +436,7 @@
|
||||
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_others" />
|
||||
<Preference android:title="Custom double tap length" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Disable pip notification" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Header" android:summary="@string/revanced_header_default" android:selectable="false"/>
|
||||
<Preference android:title="Hide double tap overlay filter" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Hide tooltip content" android:summary="@string/revanced_patches_excluded" android:selectable="false"/>
|
||||
<Preference android:title="Icons" android:summary="@string/revanced_icons_default" android:selectable="false"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user