Private Sub AddChecklist
Dim mChecklist as Map
mChecklist.Initialize
'B4XPages.MainPage.ObtenerLocalizacion
Dim lastCalled As String = "tipo" 'We save the last pf (preference dialog) showed. The last pf showed must contain some value to stop the Do Until. In this case, a field called "site"
Dim json_torre As Map
Dim file_json As String
Wait For(ShowForm(lastCalled)) Complete (Result As Int)
Do Until ("#@" <> mChecklist.GetDefault("site", "#@") Or Result <> xui.DialogResponse_Positive) 'I use #@ as a strange string
lastCalled = mDialogs.Get(lastCalled)
Log(lastCalled & ".json")
file_json = lastCalled & ".json"
If File.Exists(File.DirAssets, file_json.ToLowerCase) Then
Log("json file doesn't exist")
Log(json_torre)
Wait For(ShowForm(lastCalled)) Complete (Result As Int)
Else
B4XPages.MainPage.toast.Initialize(Root)
B4XPages.MainPage.toast.pnl.Color = xui.Color_Green
B4XPages.MainPage.toast.DefaultTextColor = xui.Color_White
B4XPages.MainPage.toast.Show("This option doesn't exist yet")
Log("Error, json not found")
Result = xui.DialogResponse_Negative
End If
Loop
If Result = xui.DialogResponse_Positive Then
Log("mChecklist: & " & mChecklist)
Dim f As String = mChecklist.Get("Torre Modelizada") & ".json"
If File.Exists(File.DirAssets, f.ToLowerCase) Then
Dim s1 As String = File.ReadString(File.DirAssets, f.ToLowerCase)
Log("s1: " & s1)
Dim m As Map = s1.As(JSON).ToMap 'ignore
For Each Key As String In mChecklist.Keys
m.Put(Key, mChecklist.Get(Key))
Next
json_torre = m
Else
Log("Theres no model for this tower")
' toast.Show("Theres no model for this tower")
json_torre = mChecklist
End If
B4XPages.MainPage.SQL1.ExecNonQuery2($"INSERT INTO `cve` (`site`, `json_data`) VALUES (?,?)"$, Array As Object(mChecklist.Get("site"), json_torre.As(JSON).ToString))
'clvChecklist.AddTextItem(mChecklist.Get("site") & " " & mChecklist.Get("tipo") & " " & mChecklist.Get("CVE"), json_torre)
clvChecklist.Add(CreateListItem(json_torre, clvChecklist.AsView.Width, 80dip), json_torre)
End If
End Sub
Public Sub ShowForm (pf As String) As ResumableSub
Log("Load: " & pf & ".json")
pfChecklist = B4XPages.MainPage.ViewsCache1.CreatePreferencesDialog(Root, pf & ".json")
Wait For (pfChecklist.ShowDialog(mChecklist, "OK", "Cancel")) Complete (Result As Int)
Return Result
End Sub