Uh oh!
There was an error while loading. Please reload this page.
ADFA-2693: Preview include tags - #912
Conversation
📝 Walkthrough
Risks / Best-practice notes:
WalkthroughPropagates an optional basePath from activities through DesignEditor into XmlLayoutParser to resolve relative includes; XmlLayoutParser now loads and merges included XML files and recognizes/marks blocks; XmlLayoutGenerator emits elements during generation. Changes
Sequence Diagram(s)sequenceDiagram
participant Activity as EditorActivity/PreviewLayoutActivity
participant DesignEditor
participant Parser as XmlLayoutParser
participant FS as FileSystem
participant Conv as ConvertImportedXml
rect rgba(200,230,255,0.5)
Activity->>Activity: compute basePath from layout file path
Activity->>DesignEditor: loadLayoutFromParser(xml, basePath)
DesignEditor->>Parser: new XmlLayoutParser(context, basePath)
Parser->>Parser: parseFromXml(xml)
alt include tag present (layout attr)
Parser->>FS: read referenced XML (basePath + layout)
FS-->>Parser: file content / error
Parser->>Conv: ConvertImportedXml(file content)
Conv-->>Parser: converted XML
Parser->>Parser: parseFromXml(converted XML) (recursive)
Parser->>Parser: merge include attributes into parsed view
end
alt merge marker created
Parser->>Parser: wrap and mark with tools:is_xml_merge
end
Parser-->>DesignEditor: root view returned
DesignEditor-->>Activity: layout loaded (undo/redo updated)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/tools/XmlLayoutParser.kt (1)
65-91:⚠️ Potential issue | 🟠 MajorAvoid clearing global IdManager during nested include parsing.
parseFromXml()callsclear()unconditionally, so every included layout parse wipes IDs collected from earlier includes. With multiple<include>tags, only the last include’s IDs survive, leading to collisions and incorrect ID mapping.Consider making ID reset/registration optional for nested parses and disabling it for includes.
🛠️ Suggested fix (skip ID reset/registration for nested parses)
-fun parseFromXml(- xml: String,- context: Context,-) {+fun parseFromXml(+ xml: String,+ context: Context,+ resetIds: Boolean = true,+) { listViews.clear() viewAttributeMap.clear() - clear()+ if (resetIds) clear() ... - for ((view, map) in viewAttributeMap) {- if (map.contains("android:id")) {- addNewId(view, map.getValue("android:id"))- }- applyAttributes(view, map)- }+ for ((view, map) in viewAttributeMap) {+ if (resetIds && map.contains("android:id")) {+ addNewId(view, map.getValue("android:id"))+ }+ applyAttributes(view, map)+ } }layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/editor/DesignEditor.kt (1)
453-474:⚠️ Potential issue | 🟠 MajorPreserve basePath for undo/redo reloads.
loadLayoutFromParsernow acceptsbasePath, but undo/redo still call it with the default null. That breaks<include>resolution after undo/redo operations.Cache the last base path and reuse it when loading from history.
🛠️ Suggested fix (cache basePath)
class DesignEditor : LinearLayout { + private var lastBasePath: String? = null ... - fun loadLayoutFromParser(xml: String, basePath: String? = null) {+ fun loadLayoutFromParser(xml: String, basePath: String? = null) {+ lastBasePath = basePath clearAll() if (xml.isEmpty()) return val parser = XmlLayoutParser(context, basePath) ... } ... fun undo() { if (undoRedoManager == null) return - if (undoRedoManager!!.isUndoEnabled) loadLayoutFromParser(undoRedoManager!!.undo())+ if (undoRedoManager!!.isUndoEnabled) loadLayoutFromParser(undoRedoManager!!.undo(), lastBasePath) } fun redo() { if (undoRedoManager == null) return - if (undoRedoManager!!.isRedoEnabled) loadLayoutFromParser(undoRedoManager!!.redo())+ if (undoRedoManager!!.isRedoEnabled) loadLayoutFromParser(undoRedoManager!!.redo(), lastBasePath) } }
🤖 Fix all issues with AI agents
In
`@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/activities/EditorActivity.kt`:
- Around line 759-760: The restore path loses the basePath used for includes
because you pass parentPath only on initial load
(binding.editorLayout.loadLayoutFromParser(design, parentPath)) but later calls
in restoreOriginalXmlIfNeeded call loadLayoutFromParser without the basePath;
cache the resolved parentPath (e.g., store it on the Activity or EditorLayout
instance when you first compute parentPath) and reuse that cached basePath when
calling loadLayoutFromParser inside restoreOriginalXmlIfNeeded so <include>
resolution remains consistent after discard/restore.
In
`@layouteditor/src/main/java/org/appdevforall/codeonthego/layouteditor/tools/XmlLayoutParser.kt`:
- Around line 129-207: The included layout handling must merge the included
parser’s viewAttributeMap into the parent and correctly handle <merge> roots:
after creating and parsing includedParser (XmlLayoutParser.parseFromXml) iterate
includedParser.viewAttributeMap and for each entry add the corresponding child
View(s) from includedParser.root(s) into the parent listViews (or wrap multiple
roots in a synthetic container) and copy/merge their AttributeMap values into
the parent viewAttributeMap (preserving MARKER_IS_INCLUDE and any overridden
attributes from the <include> tag). Also detect when the included layout root
was a <merge> (or when includedParser exposes multiple roots) and in that case
add all parsed child Views instead of only includedParser.root, applying
attribute overrides per child; ensure the fallback placeholder branch still
merges attributes into the correct viewAttributeMap entries rather than losing
metadata.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
* feat(ADFA-2693): Parse include tags * fix(ADFA-2693) Resolve undo/redo issues with included layouts * fix(ADFA-2693): Resolve issue with included layout preview * feat(ADFA-2693): Parse merge tags * refactor(ADFA-2693): Extract parsing logic
Properly handle
<include>tags when previewing layouts