@@ -8,6 +8,12 @@ import com.squareup.workflow1.traceviewer.model.Node
8
8
import io.github.vinceglb.filekit.PlatformFile
9
9
import io.github.vinceglb.filekit.readString
10
10
11
+ /*
12
+ The root workflow Node uses an ID of 0, and since we are filtering childrenByParent by the
13
+ parentId, the root node has a parent of -1 ID. This is reflected seen inside android-register
14
+ */
15
+ const val ROOT_ID : String = " -1"
16
+
11
17
/* *
12
18
* Parses a given file's JSON String into a list of [Node]s with Moshi adapters. Each of these nodes
13
19
* count as the root of a tree which forms a Frame.
@@ -52,25 +58,28 @@ private fun createMoshiAdapter(): JsonAdapter<List<List<Node>>> {
52
58
53
59
/* *
54
60
* We take an unparsed render pass and build up a tree structure from it to form a Frame.
61
+ *
62
+ * @return Node the root node of the tree for that specific frame.
55
63
*/
56
64
private fun getFrameFromRenderPass (renderPass : List <Node >): Node {
57
- val childrenByParent = renderPass.groupBy { it.parent }
58
- val root = childrenByParent[" root " ]?.single()
65
+ val childrenByParent: Map < String , List < Node >> = renderPass.groupBy { it.parentId }
66
+ val root = childrenByParent[ROOT_ID ]?.single()
59
67
return buildTree(root!! , childrenByParent)
60
68
}
61
69
62
70
/* *
63
71
* Recursively builds a tree using each node's children.
64
72
*/
65
73
private fun buildTree (node : Node , childrenByParent : Map <String , List <Node >>): Node {
66
- val children = (childrenByParent[node.name ] ? : emptyList())
74
+ val children = (childrenByParent[node.id ] ? : emptyList())
67
75
return Node (
68
76
name = node.name,
77
+ id = node.id,
69
78
parent = node.parent,
79
+ parentId = node.parentId,
70
80
props = node.props,
71
81
state = node.state,
72
82
children = children.map { buildTree(it, childrenByParent) },
73
- id = node.id
74
83
)
75
84
}
76
85
0 commit comments