chrisbanes / tivi

Tivi is a TV show tracking Android app, which connects to trakt.tv
Apache License 2.0
6.6k stars 877 forks source link

Why do you use doOnLayout on Glide? #258

Closed bernaferrari closed 5 years ago

bernaferrari commented 5 years ago

Hi, I love your app, it has helped me a lot, but I am lazy to get the keys and test it on my phone. Most of DataBinding I learned by copying and modifying things from your app. Today, I implemented some new things and had a very weird issue: Glide displaying wrong images. After a lot of debugging, I found the doOnLayout wasn't being called when recycling. It works on some cases for me, but not on all of them, and my setup is similar to yours (mvrx, epoxy, databinding, etc). I removed it, and everything got fine.

So... It is not an "issue", but I also have nowhere else to ask and you are a bigger expert on databinding than me: why do you use the doOnLayout? Is it safe to remove it? Most tutorials don't include it, but you are a bigger expert than most people.

https://github.com/chrisbanes/tivi/blob/932713c01abdf3cf95ddda8d55865b864f63bd3a/app/src/main/java/app/tivi/ui/databinding/TiviBindingAdapters.kt#L34

markus2610 commented 5 years ago

You get the right width after measuring.

bernaferrari commented 5 years ago

but Glide works fine even without it

chrisbanes commented 5 years ago

Glide does yes, but the image URL I request changes based on the size of the view: urlProvider.getPosterUrl(path, it.width)

bernaferrari commented 5 years ago

Oooooh, that makes sense, thanks!!