Support special Android layout XML tags: fragment, include, merge
This commit is contained in:
+5
@@ -47,3 +47,8 @@ public fun isResourceIdDeclaration(str: String?): Boolean = str?.startsWith(Andr
|
||||
public fun isResourceIdUsage(str: String?): Boolean = str?.startsWith(AndroidConst.ID_USAGE_PREFIX) ?: false
|
||||
|
||||
public fun isResourceDeclarationOrUsage(id: String?): Boolean = isResourceIdDeclaration(id) || isResourceIdUsage(id)
|
||||
|
||||
public fun getRealWidgetType(xmlType: String): String = when (xmlType) {
|
||||
"fragment", "include", "merge" -> "View"
|
||||
else -> xmlType
|
||||
}
|
||||
+5
-5
@@ -32,11 +32,11 @@ class AndroidXmlHandler(private val elementCallback: (String, String) -> Unit) :
|
||||
|
||||
override fun startElement(uri: String, localName: String, qName: String, attributes: Attributes) {
|
||||
val attributesMap = attributes.toMap()
|
||||
val idAttr = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
|
||||
val classNameAttr = attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName
|
||||
if (isResourceDeclarationOrUsage(idAttr)) {
|
||||
val name = idToName(idAttr)
|
||||
if (name != null) elementCallback(name, classNameAttr)
|
||||
val idAttribute = attributesMap[AndroidConst.ID_ATTRIBUTE_NO_NAMESPACE]
|
||||
val widgetType = getRealWidgetType(attributesMap[AndroidConst.CLASS_ATTRIBUTE_NO_NAMESPACE] ?: localName)
|
||||
if (isResourceDeclarationOrUsage(idAttribute)) {
|
||||
val name = idToName(idAttribute)
|
||||
if (name != null) elementCallback(name, widgetType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user