0

I am working on an application that has this image gallery activity where images are loaded from disk using Glide. These images are downloaded separately through DownloadManager. The problem is that these images might not have been downloaded by the time the user opens the gallery. I guess one way would be to load these images dynamically once each file gets downloaded by going through a BroadcastReceiver but I am wondering if there is an easier solution? Some of the images only shows parts of itself while others don't show at all, and in order to view the full images I have to navigate back into the gallery so that Glide can redo the loading. I would instead like the images to be displayed once they are able to load. I also tried using a placeholder but it will never be replaced by the image (I would also like to avoid using a placeholder image since I don't have any). The images are displayed in a GridView and loaded in getView method of a BaseAdapter. (Currently I also have to avoid storing the images in cache otherwise the incomplete images will be shown the next time as well). Code:

    val file = File(urls[position].toString())
    Glide.with(context)
            .asBitmap()
            .load(file)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .skipMemoryCache(true)
            .fitCenter()
            .apply(RequestOptions())
            .into(imageView)
axlrtr
  • 535
  • 6
  • 23
  • Use a [listener](https://stackoverflow.com/a/47790836/8244632). – Lalit Fauzdar Jul 03 '20 at 09:43
  • In that case only images not yet downloaded will show up correctly, while the first images which are partly downloaded only will show part of their image. – axlrtr Jul 03 '20 at 10:14
  • Downloading images using Glide and loading them only when downloaded will do the trick. Listener will still be used. – Lalit Fauzdar Jul 03 '20 at 11:00
  • For those who are finding this same issue with Glide 4, simply using a listener to set will not work. https://github.com/bumptech/glide/blob/master/library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java#L24 Settings is already happening after listening for full load in the latest Glide version. – Tony Dec 16 '21 at 18:46

0 Answers0