Skip to content

Commit

Permalink
feat: Publicize resource utility functions
Browse files Browse the repository at this point in the history
This commit adds the functions to the public API
  • Loading branch information
oSumAtrIX committed Aug 24, 2023
1 parent 47eac14 commit 20aff26
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/kotlin/app/revanced/util/resources/ResourceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.w3c.dom.Node
import java.nio.file.Files
import java.nio.file.StandardCopyOption

internal object ResourceUtils {
@Suppress("MemberVisibilityCanBePrivate")
object ResourceUtils {

/**
* Merge strings. This manages [StringResource]s automatically.
*
* @param host The hosting xml resource. Needs to be a valid strings.xml resource.
*/
internal fun ResourceContext.mergeStrings(host: String) {
fun ResourceContext.mergeStrings(host: String) {
this.iterateXmlNodeChildren(host, "resources") {
// TODO: figure out why this is needed
if (!it.hasAttributes()) return@iterateXmlNodeChildren
Expand All @@ -32,10 +33,11 @@ internal object ResourceUtils {

/**
* Copy resources from the current class loader to the resource directory.
*
* @param sourceResourceDirectory The source resource directory name.
* @param resources The resources to copy.
*/
internal fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
fun ResourceContext.copyResources(sourceResourceDirectory: String, vararg resources: ResourceGroup) {
val classLoader = ResourceUtils.javaClass.classLoader
val targetResourceDirectory = this["res"]

Expand All @@ -55,15 +57,15 @@ internal object ResourceUtils {
* @param resourceDirectoryName The name of the directory of the resource.
* @param resources A list of resource names.
*/
internal class ResourceGroup(val resourceDirectoryName: String, vararg val resources: String)
class ResourceGroup(val resourceDirectoryName: String, vararg val resources: String)

/**
* Iterate through the children of a node by its tag.
* @param resource The xml resource.
* @param targetTag The target xml node.
* @param callback The callback to call when iterating over the nodes.
*/
internal fun ResourceContext.iterateXmlNodeChildren(
fun ResourceContext.iterateXmlNodeChildren(
resource: String,
targetTag: String,
callback: (node: Node) -> Unit
Expand Down

0 comments on commit 20aff26

Please sign in to comment.