2

In my app I am getting image from my server into Imageview. I using this code:

 try {
            GlideApp.with(mContext)
                    .load(myCard.url)
                    .placeholder(R.drawable.no_connection)
                    .apply(new RequestOptions().centerCrop())
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .skipMemoryCache(true)
                    .into(arkafon);
        } catch (Exception e) {
            e.printStackTrace();
        }

it works but each time app download images as a new one so internet usage increasing. is that posibble to check if image is changed, app should download new one. otherwise if there is NO change at image app should use downloaded before image.

mehmet
  • 1,558
  • 5
  • 30
  • 41

3 Answers3

4

If you want load new image with same name as previously loaded file than you must have one field which will define image uniqueness. I am giving you a example for it : suppose you have profile image with url , so you need one more flag which tell's us about last updated date and time if you have that uniqueness than you can load image on basis of it by below code. In below example i have lastModified is unique fields.

Glide.with(this)
        .load(avatarFile)
        .diskCacheStrategy(DiskCacheStrategy.RESULT)
        .signature(new StringSignature(String.valueOf(avatarFile.lastModified())))
        .into(ivProfile);
Rujul Gandhi
  • 1,700
  • 13
  • 28
0

it looks ugly but this is my solution

import java.util.Calendar;
import java.util.Date;

Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        try {
            GlideApp.with(mContext)
                    .load(myCard.url)
                    .placeholder(R.drawable.no_connection)
                    .apply(new RequestOptions().centerCrop())
                    .signature(new ObjectKey(String.valueOf(cal.get(Calendar.MONTH))))
                    .into(arkafon);
        } catch (Exception e) { 
        }

it will update all images monthly, if you want earlier you can use Calendar.WEEK_OF_YEAR

mehmet
  • 1,558
  • 5
  • 30
  • 41
0

I also face this problem, and finally I find this issue, to solve the problem. Refer to this Glide issue

My code is like this. And the DataSave is a util class for SharedPreferences.

String oldSignature = DataSave.readData(signatureKey);
String newSignature = String.valueOf(System.currentTimeMillis());
DataSave.saveData(signatureKey, newSignature);

Glide.with(context)
        .load(glideUrl)
        .thumbnail(Glide.with(context)
                .load(glideUrl)
                .signature(new ObjectKey(oldSignature)))
        .signature(new ObjectKey(newSignature))
        .placeholder(placeHolder)
        .error(placeHolder)
        .listener(listener)
        .into(imageView);