Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set visibility of progress bar gone on completion of image loading using Glide library

Hi I want to have a progress bar for image which will shown while image loading but when image loading will be completed I want to set it to gone. Earlier I was using Picasso library for this. But I don't know how to use it with Glide library. I have idea that some resource ready function is there but I don't know how to use it. Can anyone help me?

Code for Picasso Library

Picasso.with(mcontext).load(imgLinkArray.get(position).mUrlLink)        .into(imageView, new Callback() {            @Override            public void onSuccess() {                progressBar.setVisibility(View.GONE);            }             @Override            public void onError() {            }         }) ; 

Now How Can I do this with Glide?

Glide.with(mcontext).load(imgLinkArray.get(position).mUrlLink)      .into(imageView); 

I am able to load image by this with Glide but how can I write progressBar.setVisibility(View.GONE); somewhere in code if image get loaded?

like image 247
HariRam Avatar asked Sep 26 '14 07:09

HariRam


People also ask

How does Android image loading library glide and fresco work?

If present in the disk cache, it loads the bitmap from the disk, also puts it in the memory cache and load the bitmap into the view. If not present in the disk cache, it downloads the image from the network, puts it in the disk cache, also puts it in the memory cache and load the bitmap into the view.

Does glide cache images?

Glide enables effective loading and caching of images. You can load images from a variety of sources such as files URIs, Android resources, bitmaps, drawables, etc. Just use the load() method to receive images.


2 Answers

Question is rather old, and I don't know what was the situation with glide in those times, but now it can be easily done with listener (not as proposed in the answer chosen as correct).

progressBar.setVisibility(View.VISIBLE); Glide.with(getActivity())      .load(args.getString(IMAGE_TO_SHOW))      .listener(new RequestListener<String, GlideDrawable>() {          @Override          public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {              return false;          }           @Override          public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {              progressBar.setVisibility(View.GONE);              return false;          }      })      .into(imageFrame) ; 

You return true if want to handle things like animations yourself and false if want glide to handle them for you.

like image 198
Yaroslav Avatar answered Sep 20 '22 07:09

Yaroslav


If you want to do this in KOTLIN, you can try that way:

    Glide.with(context)             .load(url)             .listener(object : RequestListener<Drawable> {                 override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {                     //TODO: something on exception                 }                 override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {                     Log.d(TAG, "OnResourceReady")                     //do something when picture already loaded                     return false                 }             })             .into(imgView) 
like image 29
Paulina Avatar answered Sep 20 '22 07:09

Paulina