Skip to content

Instantly share code, notes, and snippets.

@ataulm
Created July 17, 2020 13:34
Show Gist options
  • Save ataulm/84d52077c2943bd3218cc64a4ea01cd8 to your computer and use it in GitHub Desktop.
Save ataulm/84d52077c2943bd3218cc64a4ea01cd8 to your computer and use it in GitHub Desktop.
internal fun Attr.belongsToItem() = ownerElement.nodeName == "item"
internal fun Element.belongsToStyle() = parentNode.nodeName == "style"
internal fun Element.belongsToThemeOrThemeOverlay() = belongsToStyle()
&& parentNode.attributes.getNamedItem("name").nodeValue.startsWith("Theme")
/**
* Looks for VALUE in a <style> resource
* e.g. <item name="attrName">VALUE</item>
* else returns null
*/
internal fun Element.findValueOfItemWithName(attrName: String): String? {
if (nodeName != "style") throw IllegalArgumentException("Expected <style> element but found: $nodeName")
return getChildren(this)
.firstOrNull { element -> element.nodeName == "item" && element.getAttribute("name") == attrName }
?.firstChild
?.nodeValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment