Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delayed loading of images on cards

I'm specifically looking at doing this in a CardScrollAdapter, but it would be also good to know in the LiveCard situation when publishing a card to the timeline. Is there a way to use volley or any other networking library to load images using the generic Card class?

like image 498
yincrash Avatar asked Mar 22 '23 08:03

yincrash


1 Answers

While you can't use Volley's NetworkImageView class directly with a Card (because the Card manages its own layout), you should be able to use other features in Volley to handle delay-loading your images.

At a high-level, you could use an approach like this:

  1. When you create your Card, have it initially use a placeholder image if the desired image isn't already available (cached somewhere). Keep track of the instance of the Card somewhere (in the adapter, for example).
  2. Enqueue a request to load the image.
  3. Once the image has been retrieved, write the image out to your application's cache directory and add it to the card using a file: URL.
  4. Call Card.toView() again to regenerate the card's views and update your UI as needed.
like image 130
Tony Allevato Avatar answered Mar 23 '23 23:03

Tony Allevato