diff --git a/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/LayoutInflaterImpl.kt b/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/LayoutInflaterImpl.kt index 5fc6ee35e..1a5cbe5cf 100644 --- a/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/LayoutInflaterImpl.kt +++ b/xml-inflater/src/main/java/com/itsaky/androidide/inflater/internal/LayoutInflaterImpl.kt @@ -65,6 +65,7 @@ open class LayoutInflaterImpl : ILayoutInflater { override var inflationEventListener: IInflateEventsListener? = null override var module: AndroidModule? = null + private var manuallyStartedParse = false private var _primaryInflatingFile: File? = null private var _currentLayoutFile: LayoutFile? = null @@ -95,7 +96,11 @@ open class LayoutInflaterImpl : ILayoutInflater { this.inflationEventListener = null this._primaryInflatingFile = null this._currentLayoutFile = null - endParse() + + if (manuallyStartedParse) { + // end the pare only if we called startParse() + endParse() + } } protected open fun doInflate(file: File, parent: ViewGroup): List { @@ -187,7 +192,7 @@ open class LayoutInflaterImpl : ILayoutInflater { } else { onCreatePlatformView(widget, parentView, module, widgets) }) - as ViewImpl + as ViewImpl addNamespaceDecls(element, view) applyAttributes(element, view, parent) @@ -271,13 +276,13 @@ open class LayoutInflaterImpl : ILayoutInflater { } val (processor, module) = processXmlFile(file) - + // we need to restore the layout file instance as well val inflated = currentLayoutFile.let { layoutFile -> doInflate(processor, module) { parent }.also { _currentLayoutFile = layoutFile } } - + if (inflated.isEmpty() || inflated.size > 1) { // probably a merged view or no views at all // no need to apply attributes @@ -377,13 +382,16 @@ open class LayoutInflaterImpl : ILayoutInflater { } else { startParse(this.module!!) } + this.manuallyStartedParse = true + } else { + manuallyStartedParse = false } inflationEventListener?.onEvent(InflationStartEvent()) } private fun wrap(parent: ViewGroup): IViewGroup { return componentFactory.createView(currentLayoutFile, parent.javaClass.name, parent) - as IViewGroup + as IViewGroup } private fun SourcePosition.lineCol(): String {