Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crossfade animation animates on already loaded image #228

Closed
cnordvik opened this issue Oct 31, 2014 · 3 comments
Closed

Crossfade animation animates on already loaded image #228

cnordvik opened this issue Oct 31, 2014 · 3 comments
Labels

Comments

@cnordvik
Copy link

I read here #132 that it states:
"the 3.x version of Glide simply relies on existing images to be in cache, but otherwise treats every new load equally, even if the new load is for an image that is already being displayed."

I migrated from Picasso to Glide and have the issue now that my news images display fine when viewing them, but then seem to be fetched again and a crossfade animation occurs between the old cached image and the new image which are equal.

  1. Why does it fetch the image again if it is already in the cache?
  2. If somehow this cannot be avoided, how can I make it not do the crossfade between two equal images?

Since it is news images, the images won't change so we don't want to fetch the images if they exist on disk already.

Here is my code:

final String imageUrl = TopNewsDetailsFragment.getBestImage(me, m_activity);
    if (imageUrl.length() > 0)
        Glide.with(m_activity)
                .load(imageUrl)
                .placeholder(R.drawable.empty_newsitem)
                .error(R.drawable.empty_newsitem)
                .into(holder.image);
@TWiStErRob
Copy link
Collaborator

TWiStErRob commented Oct 31, 2014

  1. it doesn't fetch again, it's just not using the fact that it's from the cache or just been downloaded: "treats every new load equally" so the animation happens. If it really downloads again, then maybe your cache is too small.

2.1 There's a .noTransform() which prevents the crossfade.

2.2 I think not adding a .placeholder() can also help, since placeholder is set even if you have an image there and now loading the same so the flow is: no image -> placeholder -> image -> placeholder -> image; you can just set the placeholder in the xml to be the default src: placeholder -> image -> image.

2.3 See https://github.com/TWiStErRob/random/tree/master/GlideSongs TWiStErRob/repros@c314eb9 for "minimal" example and TWiStErRob/random#1 TWiStErRob/repros@117d0ba for a possible solution. Note that a TransitionDrawable cannot be put inside a TransitionDrawable!

@cnordvik
Copy link
Author

After some more investigation it turned out that since I fetched the content twice (once from cache and once from the web) and therefore called notifyDataSetChanged() twice, I got this double animation the first time it loaded. So I think I can live with this even though Picasso worked fine in this scenario :-)

@sjudd
Copy link
Collaborator

sjudd commented Oct 31, 2014

In theory the animation won't run again if the image you're loading has the same cache key (same url, identical Glide options) as an image present in the cache.

If you're loading once from cache and once from the web, are your cache keys/urls/file paths different for the cache fetch and the web fetch? This does sound like something we'd want to fix, so feel free to re-open if you have time to help us investigate a bit more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants