@@ -58,7 +58,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
5858
5959 private var _viewInfo : ViewInfoSheet ? = null
6060 private val touchSlop by lazy { get(requireContext()).scaledTouchSlop }
61- private val inflater by lazy { UiLayoutInflater () }
6261
6362 private val viewInfo: ViewInfoSheet
6463 get() = this ._viewInfo ? : ViewInfoSheet ().also { _viewInfo = it }
@@ -86,7 +85,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
8685
8786 private val hierarchyHandler by lazy { WorkspaceViewHierarchyHandler () }
8887 private val attrHandler by lazy { WorkspaceViewAttrHandler () }
89- private val inflationHandler by lazy { WorkspaceLayoutInflationHandler () }
9088
9189 companion object {
9290 const val DRAGGING_WIDGET = " DRAGGING_WIDGET"
@@ -105,7 +103,6 @@ class DesignerWorkspaceFragment : BaseFragment() {
105103 this .binding = FragmentDesignerWorkspaceBinding .inflate(inflater, container, false )
106104 hierarchyHandler.init (this )
107105 attrHandler.init (this )
108- inflationHandler.init (this )
109106 return this .binding!! .root
110107 }
111108
@@ -115,7 +112,12 @@ class DesignerWorkspaceFragment : BaseFragment() {
115112 viewModel._workspaceScreen .observe(viewLifecycleOwner) { binding?.flipper?.displayedChild = it }
116113 viewModel._errText .observe(viewLifecycleOwner) { binding?.errText?.text = it }
117114
118- inflater.inflationEventListener = this .inflationHandler
115+ val inflationHandler = WorkspaceLayoutInflationHandler ()
116+ inflationHandler.init (this )
117+
118+ val inflater = UiLayoutInflater ()
119+ inflater.inflationEventListener = inflationHandler
120+
119121 val inflated =
120122 try {
121123 inflater.inflate(viewModel.file, workspaceView).also {
@@ -126,6 +128,9 @@ class DesignerWorkspaceFragment : BaseFragment() {
126128 viewModel.errText = " ${e.message}${e.cause?.message?.let { " \n $it " } ? : " " } "
127129 viewModel.layoutHasError = true
128130 emptyList()
131+ } finally {
132+ inflationHandler.release()
133+ inflater.close()
129134 }
130135
131136 if (inflated.isEmpty() && ! viewModel.layoutHasError) {
@@ -140,11 +145,10 @@ class DesignerWorkspaceFragment : BaseFragment() {
140145 override fun onDestroyView () {
141146 super .onDestroyView()
142147 this .binding = null
148+ this ._viewInfo ?.dismiss()
143149 this ._viewInfo = null
144150 this .hierarchyHandler.release()
145151 this .attrHandler.release()
146- this .inflationHandler.release()
147- this .inflater.close()
148152 }
149153
150154 internal fun setupView (view : IView ) {
0 commit comments