Skip to content

Commit 6f0a111

Browse files
Copy xml during patching
1 parent 78d0be4 commit 6f0a111

File tree

4 files changed

+16
-55
lines changed

4 files changed

+16
-55
lines changed

patches/src/main/kotlin/app/revanced/patches/shared/layout/branding/BaseCustomBrandingPatch.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.util.logging.Logger
1414

1515
private const val REVANCED_ICON = "ReVanced*Logo" // Can never be a valid path.
1616

17-
internal val mipmapDirectories = arrayOf(
17+
private val mipmapDirectories = arrayOf(
1818
// Target app does not have ldpi icons.
1919
"mdpi",
2020
"hdpi",
@@ -101,6 +101,7 @@ internal fun baseCustomBrandingPatch(
101101

102102
execute {
103103
val iconPathTrimmed = iconPath!!.trim()
104+
104105
if (iconPathTrimmed == REVANCED_ICON) {
105106
val mipmapIconResourceGroups = mipmapDirectories.map { directory ->
106107
ResourceGroup(
@@ -150,7 +151,7 @@ internal fun baseCustomBrandingPatch(
150151
}
151152
}
152153

153-
// Copy all monochrome icons if provided.
154+
// Replace monochrome icons if provided.
154155
monochromeIconFileNames.forEach { fileName ->
155156
val replacementMonochrome = filePath.resolve("drawable").resolve(fileName)
156157
if (replacementMonochrome.exists()) {

patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package app.revanced.patches.youtube.layout.branding
22

33
import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch
4-
import app.revanced.patches.shared.layout.branding.mipmapDirectories
54
import java.nio.file.Files
65

76
private const val APP_NAME = "YouTube ReVanced"
87

9-
private val youtubeIconResourceFileNames_19_34 = mapOf(
10-
"adaptiveproduct_youtube_foreground_color_108" to "adaptiveproduct_youtube_2024_q4_foreground_color_108",
11-
"adaptiveproduct_youtube_background_color_108" to "adaptiveproduct_youtube_2024_q4_background_color_108",
12-
)
8+
private const val ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME = "adaptiveproduct_youtube_background_color_108.xml"
9+
private const val ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME = "adaptiveproduct_youtube_foreground_color_108.xml"
1310

1411
@Suppress("unused")
1512
val customBrandingPatch = baseCustomBrandingPatch(
@@ -32,10 +29,8 @@ val customBrandingPatch = baseCustomBrandingPatch(
3229
"ringo2_adaptive_monochrome_ic_youtube_launcher.xml"
3330
),
3431
adaptiveIconFileNames = arrayOf(
35-
"adaptiveproduct_youtube_2024_q4_background_color_108.xml",
36-
"adaptiveproduct_youtube_2024_q4_foreground_color_108.xml",
37-
"adaptiveproduct_youtube_background_color_108.xml",
38-
"adaptiveproduct_youtube_foreground_color_108.xml",
32+
ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME,
33+
ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME,
3934
),
4035
legacyIconResourceFileNames = arrayOf(
4136
"ic_launcher",
@@ -54,17 +49,17 @@ val customBrandingPatch = baseCustomBrandingPatch(
5449
},
5550

5651
executeBlock = {
57-
val resourceDirectory = get("res")
58-
59-
mipmapDirectories.forEach { directory ->
60-
val targetDirectory = resourceDirectory.resolve(directory)
52+
val resourceDirectory = get("res/mipmap-anydpi")
6153

62-
youtubeIconResourceFileNames_19_34.forEach { (old, new) ->
63-
val oldFile = targetDirectory.resolve("$old.png")
64-
val newFile = targetDirectory.resolve("$new.png")
54+
// Copy adaptive icon to secondary adaptive file.
55+
arrayOf(
56+
ADAPTIVE_BACKGROUND_RESOURCE_FILE_NAME to "adaptiveproduct_youtube_2024_q4_background_color_108.xml",
57+
ADAPTIVE_FOREGROUND_RESOURCE_FILE_NAME to "adaptiveproduct_youtube_2024_q4_foreground_color_108.xml",
58+
).forEach { (old, new) ->
59+
val oldFile = resourceDirectory.resolve(old)
60+
val newFile = resourceDirectory.resolve(new)
6561

66-
Files.write(newFile.toPath(), oldFile.readBytes())
67-
}
62+
Files.write(newFile.toPath(), oldFile.readBytes())
6863
}
6964
}
7065
)

patches/src/main/resources/custom-branding/youtube/mipmap-anydpi/adaptiveproduct_youtube_2024_q4_background_color_108.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

patches/src/main/resources/custom-branding/youtube/mipmap-anydpi/adaptiveproduct_youtube_2024_q4_foreground_color_108.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)