@@ -47,58 +47,57 @@ class ActionListFragment : androidx.fragment.app.Fragment(), PageLayoutRender.On
4747 private var krScriptActionHandler: KrScriptActionHandler ? = null
4848 private var autoRunTask: AutoRunTask ? = null
4949 private var themeMode: ThemeMode ? = null
50+ private var pageLayoutRender: PageLayoutRender ? = null
51+ private lateinit var rootGroup: ListItemGroup
5052
5153 private fun setListData (
5254 actionInfos : ArrayList <NodeInfoBase >? ,
5355 krScriptActionHandler : KrScriptActionHandler ? = null,
5456 autoRunTask : AutoRunTask ? = null,
5557 themeMode : ThemeMode ? = null) {
56- if (actionInfos != null ) {
57- this .actionInfos = actionInfos
58- this .krScriptActionHandler = krScriptActionHandler
59- this .autoRunTask = autoRunTask
60- this .themeMode = themeMode
61- }
58+ this .actionInfos = actionInfos
59+ this .krScriptActionHandler = krScriptActionHandler
60+ this .autoRunTask = autoRunTask
61+ this .themeMode = themeMode
6262 }
6363
6464 override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? ,
6565 savedInstanceState : Bundle ? ): View ? {
6666 return inflater.inflate(R .layout.kr_action_list_fragment, container, false )
6767 }
6868
69- private lateinit var rootGroup: ListItemGroup
7069 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
7170 super .onViewCreated(view, savedInstanceState)
7271 this .progressBarDialog = ProgressBarDialog (this .requireActivity())
72+ renderInterface()
73+ }
7374
74- rootGroup = ListItemGroup (this .requireContext(), true , GroupNode (" " ))
75-
76- if (actionInfos != null ) {
77- PageLayoutRender (this .requireContext(), actionInfos!! , this , rootGroup)
78- val layout = rootGroup.getView()
79-
80- val rootView = (this .view?.findViewById<ScrollView ?>(R .id.kr_content))
81- rootView?.removeAllViews()
82- rootView?.addView(layout)
83- triggerAction(autoRunTask)
84- }
75+ private fun renderInterface () {
76+ val context = context ? : return
77+ val currentActionInfos = actionInfos ? : return
78+
79+ rootGroup = ListItemGroup (context, true , GroupNode (" " ))
80+ pageLayoutRender = PageLayoutRender (context, currentActionInfos, this , rootGroup)
81+
82+ val layout = rootGroup.getView()
83+ val rootView = (this .view?.findViewById<ScrollView ?>(R .id.kr_content))
84+ rootView?.removeAllViews()
85+ rootView?.addView(layout)
86+
87+ triggerAction(autoRunTask)
8588 }
8689
8790 fun updateData (
8891 newItems : List <NodeInfoBase >,
8992 actionHandler : KrScriptActionHandler ? ,
9093 themeMode : ThemeMode ?
9194 ) {
92- // Cập nhật dữ liệu nội bộ
93- this .items = newItems
95+ this .actionInfos = ArrayList (newItems)
9496 this .krScriptActionHandler = actionHandler
9597 this .themeMode = themeMode
96-
97- // Cập nhật hiển thị nếu PageLayoutRender có phương thức refresh
98- pageLayoutRender.updateData(newItems)
99-
100- // Nếu có cần cập nhật giao diện khác như header, footer
101- headerView?.let { it.visibility = if (newItems.isEmpty()) View .GONE else View .VISIBLE }
98+ if (isAdded && view != null ) {
99+ renderInterface()
100+ }
102101 }
103102
104103 private fun triggerAction (autoRunTask : AutoRunTask ? ) {
0 commit comments