Sub getNotifications
LogColor("getNotifications", xui.Color_Yellow)
B4XPages.mainpage.abrirProgresso("Loading...")
If Not(toast.IsInitialized) Then
#if b4i
wait for B4XPage_Resize (Width As Int, Height As Int)
#End If
Wait For (CreateLayout) Complete (Result1 As Object)
End If
'IF I PUT THIS SLEEP THEN IMAGES ARE SHOWN CORRECTLY
Sleep(1000)
If clvNotifications.IsInitialized Then clvNotifications.Clear
Dim job As HttpJob
job.Initialize("", Me)
job.Download("https://randomuser.me/api/?results=150&inc=name,location,picture,id,cell,email")
'job.GetRequest.SetContentType("application/json")
Wait For (job) JobDone (job As HttpJob)
Log(job.Success)
If job.Success Then
Log(job.GetString)
Dim response As Map = job.GetString.As(JSON).ToMap
Log(response)
Dim results As List = response.Get("results")
Log(results.Size)
If results.Size = 0 Then
lblNoNotifications.BringToFront
lblNoNotifications.Visible=True
Else
lblNoNotifications.SendToBack
lblNoNotifications.Visible=False
End If
For Each Result As Map In results
Dim name As Map = Result.Get("name")
Dim nameTitle As String = name.Get("title")
Dim nameFirst As String = name.Get("first")
Dim nameLast As String = name.Get("last")
Dim nameComplete As String = nameTitle & " " & nameFirst & " " & nameLast
Dim location As Map = Result.Get("location")
Dim street As Map = location.Get("street")
Dim streetName As String = street.Get("name")
Dim streetNumber As String = street.Get("number")
Dim city As String = location.Get("city")
Dim state1 As String = location.Get("state")
Dim country As String = location.Get("country")
Dim locationComplete As String = streetName & ", " & streetNumber & CRLF & city & " " & state1 & " " & country
Dim picture As Map = Result.Get("picture")
Dim pictureMedium As String = picture.Get("medium")
Dim email As String = Result.Get("email")
Dim cell As String = Result.Get("cell")
Dim id As Map = Result.Get("id")
Dim idName As String = id.Get("name")
Dim idValue As String = id.Get("value")
Dim idComplete As String = idName & idValue
Dim u As user
u.Initialize
u.id = idComplete
u.name = nameComplete
u.location = locationComplete
u.picture = pictureMedium
u.email = email
u.cell = cell
Log(u)
' PCLVnotifications.AddItem(100dip, xui.Color_Transparent, u)
Dim pnl As B4XView = xui.CreatePanel("")
pnl.SetLayoutAnimated(0, 0, 0, clvNotifications.AsView.Width, 100dip)
clvNotifications.Add(pnl, u)
Next
Else
Log("ERROR: " & job.ErrorMessage)
End If
job.Release
Log("job.Release")
' PCLVnotifications.ShowScrollBar = False 'no fast scrolling
' PCLVnotifications.ExtraItems = 15
' PCLVnotifications.Commit
B4XPages.mainpage.fecharProgresso
Log("Fim")
End Sub