refactor: move ResourceUtils.mergeStrings
to correct class
This commit is contained in:
parent
018606e983
commit
bb56037cda
|
@ -8,18 +8,14 @@ import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.ResourcePatch
|
import app.revanced.patcher.patch.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
import app.revanced.patches.shared.settings.preference.impl.*
|
||||||
import app.revanced.patches.shared.settings.preference.impl.SwitchPreference
|
|
||||||
import app.revanced.patches.shared.settings.preference.impl.TextPreference
|
|
||||||
import app.revanced.patches.shared.settings.preference.impl.InputType
|
|
||||||
import app.revanced.patches.shared.settings.preference.impl.PreferenceScreen
|
|
||||||
import app.revanced.patches.youtube.interaction.downloads.annotation.DownloadsCompatibility
|
import app.revanced.patches.youtube.interaction.downloads.annotation.DownloadsCompatibility
|
||||||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
||||||
import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomControlsResourcePatch
|
import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomControlsResourcePatch
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
import app.revanced.util.resources.ResourceUtils
|
import app.revanced.util.resources.ResourceUtils
|
||||||
import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings
|
|
||||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||||
|
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
||||||
|
|
||||||
@Name("downloads-resource-patch")
|
@Name("downloads-resource-patch")
|
||||||
@DependsOn([BottomControlsResourcePatch::class, FixLocaleConfigErrorPatch::class, SettingsPatch::class])
|
@DependsOn([BottomControlsResourcePatch::class, FixLocaleConfigErrorPatch::class, SettingsPatch::class])
|
||||||
|
|
|
@ -8,12 +8,12 @@ import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.ResourcePatch
|
import app.revanced.patcher.patch.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
|
import app.revanced.patches.shared.settings.preference.impl.Preference
|
||||||
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||||
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
|
import app.revanced.patches.youtube.layout.returnyoutubedislike.annotations.ReturnYouTubeDislikeCompatibility
|
||||||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
import app.revanced.patches.shared.settings.preference.impl.Preference
|
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
|
||||||
import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings
|
|
||||||
|
|
||||||
@DependsOn([FixLocaleConfigErrorPatch::class, SettingsPatch::class])
|
@DependsOn([FixLocaleConfigErrorPatch::class, SettingsPatch::class])
|
||||||
@Name("return-youtube-dislike-resource-patch")
|
@Name("return-youtube-dislike-resource-patch")
|
||||||
|
|
|
@ -7,16 +7,16 @@ import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.ResourcePatch
|
import app.revanced.patcher.patch.ResourcePatch
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility
|
|
||||||
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
|
||||||
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
import app.revanced.patches.shared.mapping.misc.patch.ResourceMappingPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
|
||||||
import app.revanced.patches.shared.settings.preference.impl.Preference
|
import app.revanced.patches.shared.settings.preference.impl.Preference
|
||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||||
|
import app.revanced.patches.youtube.layout.sponsorblock.annotations.SponsorBlockCompatibility
|
||||||
|
import app.revanced.patches.youtube.misc.manifest.patch.FixLocaleConfigErrorPatch
|
||||||
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
import app.revanced.util.resources.ResourceUtils
|
import app.revanced.util.resources.ResourceUtils
|
||||||
import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings
|
|
||||||
import app.revanced.util.resources.ResourceUtils.copyResources
|
import app.revanced.util.resources.ResourceUtils.copyResources
|
||||||
import app.revanced.util.resources.ResourceUtils.copyXmlNode
|
import app.revanced.util.resources.ResourceUtils.copyXmlNode
|
||||||
|
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
||||||
|
|
||||||
@Name("sponsorblock-resource-patch")
|
@Name("sponsorblock-resource-patch")
|
||||||
@SponsorBlockCompatibility
|
@SponsorBlockCompatibility
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package app.revanced.util.microg
|
package app.revanced.util.microg
|
||||||
|
|
||||||
import app.revanced.patcher.data.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.util.resources.ResourceUtils.Settings.mergeStrings
|
import app.revanced.util.resources.ResourceUtils.mergeStrings
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for applying resource patches needed for the microg-support patches.
|
* Helper class for applying resource patches needed for the microg-support patches.
|
||||||
|
|
|
@ -2,8 +2,8 @@ package app.revanced.util.resources
|
||||||
|
|
||||||
import app.revanced.patcher.data.DomFileEditor
|
import app.revanced.patcher.data.DomFileEditor
|
||||||
import app.revanced.patcher.data.ResourceContext
|
import app.revanced.patcher.data.ResourceContext
|
||||||
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
|
||||||
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
import app.revanced.patches.shared.settings.preference.impl.StringResource
|
||||||
|
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
|
||||||
import org.w3c.dom.Node
|
import org.w3c.dom.Node
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
|
@ -11,26 +11,21 @@ import java.nio.file.StandardCopyOption
|
||||||
internal object ResourceUtils {
|
internal object ResourceUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings related utilities
|
* Merge strings. This manages [StringResource]s automatically.
|
||||||
|
* @param host The hosting xml resource. Needs to be a valid strings.xml resource.
|
||||||
*/
|
*/
|
||||||
internal object Settings {
|
internal fun ResourceContext.mergeStrings(host: String) {
|
||||||
/**
|
this.iterateXmlNodeChildren(host, "resources") {
|
||||||
* Merge strings. This handles [StringResource]s automatically.
|
// TODO: figure out why this is needed
|
||||||
* @param host The hosting xml resource. Needs to be a valid strings.xml resource.
|
if (!it.hasAttributes()) return@iterateXmlNodeChildren
|
||||||
*/
|
|
||||||
internal fun ResourceContext.mergeStrings(host: String) {
|
|
||||||
this.iterateXmlNodeChildren(host, "resources") {
|
|
||||||
// TODO: figure out why this is needed
|
|
||||||
if (!it.hasAttributes()) return@iterateXmlNodeChildren
|
|
||||||
|
|
||||||
val attributes = it.attributes
|
val attributes = it.attributes
|
||||||
val key = attributes.getNamedItem("name")!!.nodeValue!!
|
val key = attributes.getNamedItem("name")!!.nodeValue!!
|
||||||
val value = it.textContent!!
|
val value = it.textContent!!
|
||||||
|
|
||||||
val formatted = attributes.getNamedItem("formatted") == null
|
val formatted = attributes.getNamedItem("formatted") == null
|
||||||
|
|
||||||
SettingsPatch.addString(key, value, formatted)
|
SettingsPatch.addString(key, value, formatted)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue