Hello,
im using the library : ImageDownloader
in a loop of a few items of a customview
I just noticed that the images are systematically downloaded from the server.
In fact, I would like to find a way to use the cache
when :
- the image already exists
- and has the same properties. (if possible, because it could be replace sometimes on the server)
the standard code that i got via that forum is :
and so, is there a setting to use the cache, in the conditions above ?
Thanks
Michel
im using the library : ImageDownloader
in a loop of a few items of a customview
I just noticed that the images are systematically downloaded from the server.
In fact, I would like to find a way to use the cache
when :
- the image already exists
- and has the same properties. (if possible, because it could be replace sometimes on the server)
the standard code that i got via that forum is :
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private cache As Map
Private tasks As Map
Private ongoingTasks As Map
End Sub
Sub Service_Create
tasks.Initialize
cache.Initialize
ongoingTasks.Initialize
End Sub
Sub Service_Start (StartingIntent As Intent)
End Sub
Sub Service_Destroy
End Sub
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)
ongoingTasks.Put(link, "")
Dim j As HttpJob
j.Initialize(link, Me)
j.Download(link)
Next
End Sub
Sub JobDone(Job As HttpJob)
ongoingTasks.Remove(Job.JobName)
If Job.Success Then
Dim bmp As Bitmap = Job.GetBitmap
cache.Put(Job.JobName, bmp)
If tasks.IsInitialized Then
For i = 0 To tasks.Size - 1
Dim link As String = tasks.GetValueAt(i)
If link = Job.JobName Then
Dim iv As ImageView = tasks.GetKeyAt(i)
iv.SetBackgroundImage(bmp)
'Log(i)
End If
Next
End If
Else
Log("Error downloading image: " & Job.JobName & CRLF & Job.ErrorMessage)
End If
Job.Release
End Sub
Sub ActivityIsPaused
tasks.Clear
End Sub
and so, is there a setting to use the cache, in the conditions above ?
Thanks
Michel