The sub that does the main work in my mineXML app is iterative. I would like to update a progress bar when importing larger files, but can't for the life of me work out how to use the wait for to achieve this when the sub calls itself.
I did try creating it in it's own class and creating new instances as needed and waited on the a complete call from the class, it worked, but the tree can be hundreds of levels deep and it added a long time to the process.
This is the sub, any ideas gratefully received.
I did try creating it in it's own class and creating new instances as needed and waited on the a complete call from the class, it worked, but the tree can be hundreds of levels deep and it added a long time to the process.
This is the sub, any ideas gratefully received.
B4X:
Private Sub XMLMapToDataDo(M As Map, Indent As Int, TagList As List)
For Each K As Object In M.Keys
Dim JO As JavaObject = "" 'Ignore
Dim Key As String = JO.RunMethod("join",Array(",",TagList))
Key = Key & "," & K
Dim FN As String = FriendlyNames.GetDefault(Key,"")
If M.Get(K) Is Map Then
Dim TL1 As List
TL1.Initialize
TL1.AddAll(TagList)
If TL1.Size = 0 Or TL1.Get(TL1.Size - 1) <> K Then TL1.Add(K)
XMLMapToDataDo(M.Get(K), Indent + 1, TL1)
Else If M.Get(K) Is List Then
Dim L As List = M.Get(K)
For Each O As Object In L
If O Is Map Then
Dim TL1 As List
TL1.Initialize
TL1.AddAll(TagList)
If TL1.Size = 0 Or TL1.Get(TL1.Size - 1) <> K Then TL1.Add(K)
XMLMapToDataDo(O,Indent + 1, TL1)
Else
If DataSaveMap.ContainsKey(Key) = False Then
Dim DS As DataSaveType1 = NewDataSaveType1(Key,"Str1",K,FN,O,False)
DataSaveMap.Put(Key,DS)
DataSaveKeyList.Add(Key)
Else
DS = DataSaveMap.Get(Key)
DS.Values.Add(O)
End If
End If
Next
Else
If DataSaveMap.ContainsKey(Key) = False Then
Dim DS As DataSaveType1 = NewDataSaveType1(Key,"Str2",K,FN,M.Get(K),False)
DataSaveMap.Put(Key,DS)
DataSaveKeyList.Add(Key)
Else
DS = DataSaveMap.Get(Key)
DS.Values.Add(M.Get(K))
End If
End If
Next
End Sub