Android Question ImageDownloader library + Cache admin

Discussion in 'Android Questions' started by ALBRECHT, Jul 15, 2019.

  1. ALBRECHT

    ALBRECHT Active Member Licensed User

    Hello,

    im using the library : ImageDownloader
    in a loop of a few items of a customview

    [​IMG]

    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 :

    Code:
    #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
     
  2. ronell

    ronell Well-Known Member Licensed User

  3. ALBRECHT

    ALBRECHT Active Member Licensed User

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

    Code:
    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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    See ImageDownloader code. It is quite simple. It caches images based on the link.
     
    Peter Simpson likes this.
  5. ALBRECHT

    ALBRECHT Active Member Licensed User

  6. Erel

    Erel Administrator Staff Member Licensed User

  7. ALBRECHT

    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 .
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    You don't need a library for that. You can implement it yourself. You can use a database and store the images as blobs.
     
    Johan Hormaza likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice