Android Question Suppress ImageDownloader ResponseError in Log

swabygw

Active Member
Licensed User
Longtime User

DonManfred

Expert
Licensed User
Longtime User
remove the log from the code.....
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
LoL - Okay, I forgot to post that I've modified the ImageDownloader.bas code - it's using the new "Wait For" feature. Here's the code in the file now:

B4X:
Sub Download (ImageViewsMap As Map)
  For i = 0 To ImageViewsMap.Size - 1
   tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
    Dim link As String = ImageViewsMap.GetValueAt(i)
    If cache.ContainsKey(link) Then
      Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
      SharedCode.FitCenterBitmap(iv, cache.Get(link))
    Else If ongoingTasks.ContainsKey(link) = False Then
      ongoingTasks.Put(link, "")
      Dim jobHttpGetImage As HttpJob
      jobHttpGetImage.Initialize(link, Me)
      jobHttpGetImage.Download(link) 'raises ResponseError error with Reason: Not Found, and Response text
      Wait For (jobHttpGetImage) JobDone(j As HttpJob)
      If j.Success Then
        Dim bmp As Bitmap = j.GetBitmap
        cache.Put(j.JobName, bmp)
        If tasks.IsInitialized Then
          For i = 0 To tasks.Size - 1
            Dim link As String = tasks.GetValueAt(i)
            If link = j.JobName Then
              Dim iv As ImageView = tasks.GetKeyAt(i)
              SharedCode.FitCenterBitmap(iv, bmp)
            End If
          Next
        End If
      Else
        Log("ImageDownloader Error")
      End If
      j.Release
    End If
  Next
End Sub

The old sub "Sub JobDone(Job As HttpJob)" is commented out.

** Sorry, trying to get the code tagged area fixed.
 
Last edited:
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
Yes - the log I've created is: Log("ImageDownloader Error"), but there's also another entry in the log that I didn't create which has the Reason and Response text. I think in the old OkHttp, it was created by the hc_ResponseError subroutine.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
That's the idea - when the URL doesn't exist (for example, the file has been deleted), I'd like to suppress the Reason and Response text.

For example, if the URL is http://www.someurl.com/deletedfile.jpg, according to the code above, the only thing in the log should be "ImageDownloader Error", but I also get the Reason and Response text, which I'd like to suppress.
 
Upvote 0

swabygw

Active Member
Licensed User
Longtime User
There's no JobDone routine in the calling bas file. I make the call from Main like this:

B4X:
Dim links As Map
links.Initialize
links.Put(iv, Starter.ServerUrl&"media/" & ImageURL)
CallSubDelayed2(ImageDownloader, "Download", links)

(I suspect that wherever HttpJob is defined, there will be the answer, but I don't know how to see where HttpJob is defined - I suspect it's build into the included OkHttp and OkHttpUtils2 libraries)
 
Upvote 0
Top