Skip to content

Commit

Permalink
calculate parent id inside the processor
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianTerhorst committed Jun 6, 2016
1 parent 019518c commit df1c0ce
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ public class LayoutEntity {

private String rootLayout;

private String parent;

public LayoutEntity() {
children = new ArrayList<>();
attributes = new ArrayList<>();
hasChildren = false;
parent = "this";
}

public void setId(String id) {
Expand All @@ -43,6 +46,10 @@ public void setRootLayout(String rootLayout) {
this.rootLayout = rootLayout;
}

public void setParent(String parent) {
this.parent = parent;
}

public void addAttribute(LayoutAttribute attribute) {
this.attributes.add(attribute);
}
Expand Down Expand Up @@ -83,6 +90,10 @@ public String getRootLayout() {
return rootLayout;
}

public String getParent() {
return parent;
}

public boolean isHasChildren() {
return hasChildren;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,28 +223,30 @@ private String getIdByNode(Node node) {
return null;
}

private List<LayoutEntity> createChildList(Node node) {
private List<LayoutEntity> createChildList(Node node, LayoutEntity parent) {
List<LayoutEntity> layouts = new ArrayList<>();
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node child = nodeList.item(i);
if (child.getAttributes() != null && child.getAttributes().getLength() > 0) {
LayoutEntity layout = createLayoutFromChild(child, node.getNodeName());
LayoutEntity layout = createLayoutFromChild(child, node.getNodeName(), parent);
mChilds.add(layout);
layouts.add(layout);
if (child.hasChildNodes()) {
createChildList(child);
createChildList(child, layout);
}
}
}
return layouts;
}

private LayoutEntity createLayoutFromChild(Node node) {
return createLayoutFromChild(node, node.getNodeName());
LayoutEntity layoutEntity = new LayoutEntity();
layoutEntity.setId("this");
return createLayoutFromChild(node, node.getNodeName(), layoutEntity);
}

private LayoutEntity createLayoutFromChild(Node node, String root) {
private LayoutEntity createLayoutFromChild(Node node, String root, LayoutEntity parent) {
final LayoutEntity layout = new LayoutEntity();
String id = getIdByNode(node);
if (id == null) {
Expand All @@ -254,6 +256,7 @@ private LayoutEntity createLayoutFromChild(Node node, String root) {
layout.setName(node.getNodeName());
layout.setHasChildren(node.hasChildNodes());
layout.setRootLayout(root);
layout.setParent(parent.getId());
layout.setLayoutParamsName(root + ".LayoutParams");

NamedNodeMap attributes = node.getAttributes();
Expand Down Expand Up @@ -547,7 +550,9 @@ private LayoutObject createLayoutObject(String layout, PackageElement packageEle
Element rootLayoutElement = document.getDocumentElement();
rootLayout = createLayoutFromChild(rootLayoutElement);
if (rootLayoutElement.hasChildNodes()) {
createChildList(rootLayoutElement);
LayoutEntity layoutEntity = new LayoutEntity();
layoutEntity.setId("this");
createChildList(rootLayoutElement, layoutEntity);
rootLayout.addChildren(mChilds);
}
} catch (Exception ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ public class ${keyWrapperClassName} extends ${rootLayout.name} implements ILayou
<#if attribute.type == "PARAM">${child.id}LayoutParams<#elseif attribute.type == "LAYOUT">${child.id}</#if>.${attribute.value};
</#if>
</#list>
<#if child.hasChildren>
this.addView(${parent}, ${parent}LayoutParams);
<#assign parent = child.id>
<#else>
${parent}.addView(${child.id}, ${child.id}LayoutParams);
</#if>
${child.parent}.addView(${child.id}, ${child.id}LayoutParams);
</#list>
}

Expand Down

0 comments on commit df1c0ce

Please sign in to comment.