refactor: better method is used for settings-framework

This commit is contained in:
inotia00
2023-02-18 01:57:06 +09:00
parent fb45389c5e
commit ef370c82d1
3 changed files with 10 additions and 25 deletions

View File

@ -18,6 +18,7 @@ import app.revanced.patches.youtube.misc.microg.shared.Constants.SPOOFED_PACKAGE
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.microg.MicroGManifestHelper.addSpoofingMetadata
import app.revanced.util.microg.MicroGResourceHelper.patchManifest
import app.revanced.util.microg.MicroGResourceHelper.patchSetting
import app.revanced.util.resources.ResourceHelper.setMicroG
@Patch
@ -49,12 +50,10 @@ class MicroGPatch : ResourcePatch {
)
SettingsPatch.updatePatchStatus("microg-support")
val settingsFragment = context["res/xml/settings_fragment.xml"]
settingsFragment.writeText(
settingsFragment.readText().replace(
"android:targetPackage=\"com.google.android.youtube",
"android:targetPackage=\"$packageName"
)
// update settings fragment
context.patchSetting(
PACKAGE_NAME,
packageName
)
// update manifest

View File

@ -16,7 +16,6 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.patches.youtube.video.customspeed.bytecode.patch.CustomVideoSpeedBytecodePatch
import app.revanced.util.resources.ResourceHelper.addSpeedEntries
import app.revanced.util.resources.ResourceHelper.addSpeedEntryValues
import app.revanced.util.resources.ResourceHelper.replaceCustomSpeed
import app.revanced.util.resources.ResourceUtils.copyXmlNode
@Patch
@ -50,8 +49,6 @@ class CustomVideoSpeedPatch : ResourcePatch {
context.addSpeedEntryValues(speedElements[index])
}
context.replaceCustomSpeed()
/*
add settings
*/

View File

@ -7,7 +7,7 @@ import org.w3c.dom.Node
import java.nio.file.Files
import java.nio.file.StandardCopyOption
private fun Node.adoptChild(tagName: String, targetNode: Node, block: Element.() -> Unit) {
private fun Node.insertNode(tagName: String, targetNode: Node, block: Element.() -> Unit) {
val child = ownerDocument.createElement(tagName)
child.block()
parentNode.insertBefore(child, targetNode)
@ -20,11 +20,11 @@ internal object ResourceHelper {
private const val TARGET_PREFERENCE_PATH = "res/xml/revanced_prefs.xml"
private const val TARGET_SETTINGS_PATH = "res/xml/settings_fragment.xml"
private const val YOUTUBE_SETTINGS_PATH = "res/xml/settings_fragment.xml"
private var targetPackage = "com.google.android.youtube"
fun setMicroG (newPackage: String) {
internal fun setMicroG (newPackage: String) {
targetPackage = newPackage
}
@ -71,17 +71,6 @@ internal object ResourceHelper {
)
}
internal fun ResourceContext.replaceCustomSpeed() {
val prefs = this[TARGET_PREFERENCE_PATH]
prefs.writeText(
prefs.readText()
.replace(
"revanced_default_video_speed_entry",
"revanced_custom_video_speed_entry"
)
)
}
internal fun ResourceContext.addPreference(settingArray: Array<String>) {
val prefs = this[TARGET_PREFERENCE_PATH]
@ -130,13 +119,13 @@ internal object ResourceHelper {
internal fun ResourceContext.addReVancedPreference(key: String) {
val targetClass = "com.google.android.apps.youtube.app.settings.videoquality.VideoQualitySettingsActivity"
this.xmlEditor[TARGET_SETTINGS_PATH].use { editor ->
this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor ->
with (editor.file) {
doRecursively loop@{
if (it !is Element) return@loop
it.getAttributeNode("android:key")?.let { attribute ->
if (attribute.textContent == "@string/about_key" && it.getAttributeNode("app:iconSpaceReserved").textContent == "false") {
it.adoptChild("Preference", it) {
it.insertNode("Preference", it) {
setAttribute("android:title", "@string/revanced_" + key + "_title")
setAttribute("android:summary", "@string/revanced_" + key + "_summary")
this.appendChild(ownerDocument.createElement("intent").also { intentNode ->