mirror of
https://github.com/revanced/revanced-patches
synced 2024-09-03 04:56:05 +02:00
fix(twitter patches.): use wider compatible Java API for writing to file (#678)
Allows running the patch on Android
This commit is contained in:
parent
fdff5efdbc
commit
4448de80a6
@ -10,6 +10,7 @@ import app.revanced.patcher.patch.PatchResultSuccess
|
||||
import app.revanced.patcher.patch.annotations.Patch
|
||||
import app.revanced.patcher.patch.impl.ResourcePatch
|
||||
import app.revanced.patches.twitter.misc.dynamiccolor.annotations.DynamicColorCompatibility
|
||||
import java.io.FileWriter
|
||||
import java.nio.file.Files
|
||||
|
||||
@Patch
|
||||
@ -28,18 +29,21 @@ class DynamicColorPatch : ResourcePatch() {
|
||||
val valuesNightV31Directory = resDirectory.resolve("values-night-v31")
|
||||
if (!valuesNightV31Directory.isDirectory) Files.createDirectories(valuesNightV31Directory.toPath())
|
||||
|
||||
listOf(valuesV31Directory, valuesNightV31Directory).forEach {
|
||||
listOf(valuesV31Directory, valuesNightV31Directory).forEach { it ->
|
||||
val colorsXml = it.resolve("colors.xml")
|
||||
|
||||
if(!colorsXml.exists()) {
|
||||
Files.writeString(
|
||||
colorsXml.toPath(),
|
||||
FileWriter(
|
||||
colorsXml,
|
||||
).use {
|
||||
it.write(
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
"<resources>\n" +
|
||||
"</resources>"
|
||||
"</resources>".trimIndent()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.xmlEditor["res/values-v31/colors.xml"].use { editor ->
|
||||
val document = editor.file
|
||||
|
@ -3,7 +3,6 @@ package app.revanced.patches.twitter.misc.monochrome.patch
|
||||
import app.revanced.patcher.annotation.Description
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.annotation.Version
|
||||
import app.revanced.patcher.data.impl.DomFileEditor
|
||||
import app.revanced.patcher.data.impl.ResourceData
|
||||
import app.revanced.patcher.patch.PatchResult
|
||||
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.impl.ResourcePatch
|
||||
import app.revanced.patches.twitter.misc.monochrome.annotations.MonochromeIconCompatibility
|
||||
import java.io.FileWriter
|
||||
import java.nio.file.Files
|
||||
|
||||
@Patch
|
||||
@ -26,8 +26,9 @@ class MonochromeIconPatch : ResourcePatch() {
|
||||
val mipmapV33Directory = resDirectory.resolve("mipmap-anydpi-v33")
|
||||
if (!mipmapV33Directory.isDirectory) Files.createDirectories(mipmapV33Directory.toPath())
|
||||
|
||||
Files.writeString(
|
||||
mipmapV33Directory.resolve("ic_launcher_twitter.xml").toPath(),
|
||||
FileWriter(
|
||||
mipmapV33Directory.resolve("ic_launcher_twitter.xml"),
|
||||
).use {
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
"<adaptive-icon\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" +
|
||||
" <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
|
||||
"</adaptive-icon>"
|
||||
)
|
||||
}
|
||||
|
||||
Files.writeString(
|
||||
mipmapV33Directory.resolve("ic_launcher_twitter_round.xml").toPath(),
|
||||
FileWriter(
|
||||
mipmapV33Directory.resolve("ic_launcher_twitter_round.xml"),
|
||||
).use {
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
|
||||
"<adaptive-icon\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" +
|
||||
" <monochrome android:drawable=\"@mipmap/ic_launcher_twitter_foreground\" />\n" +
|
||||
"</adaptive-icon>"
|
||||
)
|
||||
}
|
||||
|
||||
return PatchResultSuccess()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user