Skip to content
Permalink
Browse files

Fix Glide binding adapters

They now only request if the parameters have
actually changed. This stops the random flickering
happening due to state emissions during scrolling.
  • Loading branch information...
chrisbanes committed Aug 24, 2019
1 parent 9600a80 commit 2ca7c414185aaaf65c03b003dd0b7af64adec8c2
Showing with 27 additions and 3 deletions.
  1. +27 −3 common-glide/src/main/java/app/tivi/ui/glide/GlideBindingAdapters.kt
@@ -33,12 +33,26 @@ import app.tivi.tmdb.TmdbImageUrlProvider
)
fun loadBackdrop(
view: ImageView,
oldPath: String?,
oldUrlProvider: TmdbImageUrlProvider?,
oldSaturateOnLoad: Boolean?,
path: String?,
urlProvider: TmdbImageUrlProvider?,
saturateOnLoad: Boolean?
) {
val image = if (path != null) ShowTmdbImage(path = path, type = ImageType.BACKDROP, showId = 0) else null
loadImage(view, image, urlProvider, saturateOnLoad)
if (oldPath == path && oldUrlProvider == urlProvider && oldSaturateOnLoad == saturateOnLoad) {
return
}
if (urlProvider != null && path != null) {
view.loadTmdbImage(
ShowTmdbImage(path = path, type = ImageType.BACKDROP, showId = 0),
urlProvider,
saturateOnLoad == null || saturateOnLoad
)
} else {
view.clearRequest()
view.setImageDrawable(null)
}
}

@BindingAdapter(
@@ -49,12 +63,22 @@ fun loadBackdrop(
)
fun loadImage(
view: ImageView,
oldImage: TmdbImageEntity?,
oldUrlProvider: TmdbImageUrlProvider?,
oldSaturateOnLoad: Boolean?,
image: TmdbImageEntity?,
urlProvider: TmdbImageUrlProvider?,
saturateOnLoad: Boolean?
) {
if (oldImage == image && oldUrlProvider == urlProvider && oldSaturateOnLoad == saturateOnLoad) {
return
}
if (urlProvider != null && image != null) {
view.loadTmdbImage(image, urlProvider, saturateOnLoad == null || saturateOnLoad)
view.loadTmdbImage(
image,
urlProvider,
saturateOnLoad == null || saturateOnLoad
)
} else {
view.clearRequest()
view.setImageDrawable(null)

0 comments on commit 2ca7c41

Please sign in to comment.
You can’t perform that action at this time.