android - Cache images and show listview

4

Good afternoon friends, is as follows: I'm going to use Volley to get webservice data, and so I write the list in my local DB with SQlite.

In this webservice will come a JSON with items, each item has its data and an image. I need to save this cached image to show in a listview and later on a detail screen. In the future the user will clean these items, thus clearing the images of them too.

Well, how can I save these cached images and link to each saved item in my DB?

EDIT 1

I'll be offline by 90%. I'm just going online to sync and download updated server items.

    
asked by anonymous 22.06.2016 / 21:15

1 answer

3

As you'll take a variety of resources to make it easier to develop, use Picasso and let him manage this for you.

Through a Target you can intercept and save the image. Example:

public class MeuTarget implements Target
{
    private final WeakReference<ContentResolver> resolver;
    private final String name;
    private final String desc;

    public TargetPhoneGallery(ContentResolver r, String name, String desc)
    {
        this.resolver = new WeakReference<ContentResolver>(r);
        this.name = name;
        this.desc = desc;
    }

    @Override
    public void onPrepareLoad (Drawable arg0)
    {
    }

    @Override
    public void onBitmapLoaded (Bitmap bitmap, LoadedFrom arg1)
    {
       //sua implementacao para guardar o bitmap.
    }

    @Override
    public void onBitmapFailed (Drawable arg0)
    {
    }
}

Picasso.with(context).load(image[position]).into(new MeuTarget(view.getContentResolver(), "nome-imagem", "descricao"));
    
22.06.2016 / 21:36