HttpUtils again

madru

Active Member
Licensed User
Longtime User
Hi,

is there a way to use HttpUtil synchronous ? In my app I parse a downloaded XML file:

B4X:
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
   If parser.Parents.IndexOf("channel") > -1 Then
      If Name = "name" Then
         Title = Text.ToString
         titles.add(Title)
         Log(Title)
      Else If Name = "address" Then
         Link = Text.ToString
         links.Add(Link)
         Log(Link)
      Else If Name = "type" Then
         ctype = Text.ToString
         ctypes.Add(ctype)
         Log(ctype)
      Else If Name = "iconUrl" Then
         icon = Text.ToString ' not used
         If icon="" Then
            icon = "http://192.168.252.255/dummy.png"
         End If
         Log(icon)
         icons.Add(icon)
         icon=""
      End If
   End If
end sub


B4X:
Sub ImageUrlDone (Url As String)
If HttpUtils.IsSuccess(Url) Then
   bitmaps.Add(HttpUtils.GetBitmap(Url))
   Log("ImageUrlDone" & Url)
   HttpUtils.SuccessfulUrls.Remove(Url)
End If
End Sub
Sub ImagesJobDone
   For i = 0 To links.Size-1' HttpUtils.SuccessfulUrls.Size - 1
      lv.AddTwoLinesAndBitmap(titles.Get(i), links.Get(i),bitmaps.Get(i))
      Log(titles.Get(i) & links.Get(i)& bitmaps.Get(i))
   Next
End Sub
after parsing the XML I need to download the ICONS list and put the PNG to the associated name etc. - but that failed obviously due to the async :(


any ideas?

THX

M
 

madru

Active Member
Licensed User
Longtime User
I thought that is exactly what I do ?

B4X:
Sub HandleMainPage
   If HttpUtils.IsSuccess(ServerURL) = False Then
      ToastMessageShow("Error loading page.", True)
      Return
   End If
   in = HttpUtils.GetInputStream(ServerURL)
   parser.Parse(in, "Parser")
   HttpUtils.CallbackUrlDoneSub = "ImageUrlDone"
   HttpUtils.DownloadList("ImagesURL", icons)
End Sub
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Erel,

stripped down version attached

this shows that the numbering is not in the right order…..

THX


:)
 

Attachments

  • DL_Test.zip
    27.8 KB · Views: 185
Last edited:
Upvote 0

madru

Active Member
Licensed User
Longtime User
sorry, don't get the question, I the real App. ?

Barker channel will prepared, RTSP client will be prepared, UDP Multicast receiver will be prepared etc.

but the zip version shows the problem already…..
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
the W3 directory inside the ZIP holds all necessary files to run the example, that one needs to be on W3 server
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Erel,

forgot to give you an update :

it was clearly misunderstood from my side, my assumption that the download.list takes card of the right ordering is/was wrong :sign0148:

I solved it this way, not using ImageUrlDone at all :

B4X:
Sub ImagesURLJobDone
    For i = 0 To HttpUtils.Tasks.Size - 1
        Link = HttpUtils.Tasks.Get(i)
      bitmaps.Add(HttpUtils.GetBitmap(Link))
      lv.AddTwoLinesAndBitmap(titles.Get(i), links.Get(i),bitmaps.Get(i))
      'Log(Link & ": success=" & HttpUtils.IsSuccess(Link))
   Next
End Sub
M
 
Upvote 0
Top