Android Question ImageDownloader library + Cache admin

ALBRECHT

Active Member
Licensed User
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 :

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
 

ALBRECHT

Active Member
Licensed User
thanks Ronell, but as i have seen the script below into the standard library ImageDownloader :

B4X:
cache.Put(Job.JobName, bmp)
i thought that there already was some cache admin functions inside the B4A core (9.3) without adding other libraries
 

ALBRECHT

Active Member
Licensed User
As i said at the beginging of that post :
with the ImageDownloader
I just noticed that the images are systematically downloaded from the server, when the app is closed and then reloaded
So i was looking for a way to put on the disk cache and
reload locally rather than from remote server .
 
Top