fix(twitter patches.): use wider compatible Java API for writing to file (#678)

Allows running the patch on Android
This commit is contained in:
Aunali321 2022-09-30 20:07:40 +05:30 committed by GitHub
parent fdff5efdbc
commit 4448de80a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 26 deletions

View File

@ -10,6 +10,7 @@ import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.twitter.misc.dynamiccolor.annotations.DynamicColorCompatibility import app.revanced.patches.twitter.misc.dynamiccolor.annotations.DynamicColorCompatibility
import java.io.FileWriter
import java.nio.file.Files import java.nio.file.Files
@Patch @Patch
@ -28,18 +29,21 @@ class DynamicColorPatch : ResourcePatch() {
val valuesNightV31Directory = resDirectory.resolve("values-night-v31") val valuesNightV31Directory = resDirectory.resolve("values-night-v31")
if (!valuesNightV31Directory.isDirectory) Files.createDirectories(valuesNightV31Directory.toPath()) if (!valuesNightV31Directory.isDirectory) Files.createDirectories(valuesNightV31Directory.toPath())
listOf(valuesV31Directory, valuesNightV31Directory).forEach { listOf(valuesV31Directory, valuesNightV31Directory).forEach { it ->
val colorsXml = it.resolve("colors.xml") val colorsXml = it.resolve("colors.xml")
if(!colorsXml.exists()) { if(!colorsXml.exists()) {
Files.writeString( FileWriter(
colorsXml.toPath(), colorsXml,
).use {
it.write(
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<resources>\n" + "<resources>\n" +
"</resources>" "</resources>".trimIndent()
) )
} }
} }
}
data.xmlEditor["res/values-v31/colors.xml"].use { editor -> data.xmlEditor["res/values-v31/colors.xml"].use { editor ->
val document = editor.file val document = editor.file

View File

@ -3,7 +3,6 @@ package app.revanced.patches.twitter.misc.monochrome.patch
import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.impl.DomFileEditor
import app.revanced.patcher.data.impl.ResourceData import app.revanced.patcher.data.impl.ResourceData
import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultError
@ -11,6 +10,7 @@ import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.patch.impl.ResourcePatch import app.revanced.patcher.patch.impl.ResourcePatch
import app.revanced.patches.twitter.misc.monochrome.annotations.MonochromeIconCompatibility import app.revanced.patches.twitter.misc.monochrome.annotations.MonochromeIconCompatibility
import java.io.FileWriter
import java.nio.file.Files import java.nio.file.Files
@Patch @Patch
@ -26,8 +26,9 @@ class MonochromeIconPatch : ResourcePatch() {
val mipmapV33Directory = resDirectory.resolve("mipmap-anydpi-v33") val mipmapV33Directory = resDirectory.resolve("mipmap-anydpi-v33")
if (!mipmapV33Directory.isDirectory) Files.createDirectories(mipmapV33Directory.toPath()) if (!mipmapV33Directory.isDirectory) Files.createDirectories(mipmapV33Directory.toPath())
Files.writeString( FileWriter(
mipmapV33Directory.resolve("ic_launcher_twitter.xml").toPath(), mipmapV33Directory.resolve("ic_launcher_twitter.xml"),
).use {
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<adaptive-icon\n" + "<adaptive-icon\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + " xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
@ -35,10 +36,11 @@ class MonochromeIconPatch : ResourcePatch() {
" <foreground android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" + " <foreground android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
" <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" + " <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
"</adaptive-icon>" "</adaptive-icon>"
) }
Files.writeString( FileWriter(
mipmapV33Directory.resolve("ic_launcher_twitter_round.xml").toPath(), mipmapV33Directory.resolve("ic_launcher_twitter_round.xml"),
).use {
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<adaptive-icon\n" + "<adaptive-icon\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" + " xmlns:android=\"http://schemas.android.com/apk/res/android\">\n" +
@ -46,7 +48,7 @@ class MonochromeIconPatch : ResourcePatch() {
" <foreground android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" + " <foreground android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
" <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" + " <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
"</adaptive-icon>" "</adaptive-icon>"
) }
return PatchResultSuccess() return PatchResultSuccess()
} }