GetStream / avatarview-android

✨ Supports loading profile images with fractional styles, shapes, borders, indicators, and initials for Android.
https://getstream.github.io/avatarview-android/
Apache License 2.0
432 stars 25 forks source link

Using loadImage inside a ListAdapter onBindViewHolder #16

Open vbsteven opened 2 years ago

vbsteven commented 2 years ago

I'm trying to use AvatarView-Coil to load images inside of a ListAdapter with a ViewHolder and I'm seeing weird behavior.

Essentially in onBindViewHolder I use loadImage to load a profile picture with a String url in an AvatarView. The initial load runs fine and displays the images. Once I reload data in the adapter onBindViewHolder gets called again, but then the images are not loaded or displayed anymore.

        holder.intialsView.loadImage(favourite.contact.profilePhoto,
            onSuccess = { _, _ ->
                logi("###### onsuccess ${favourite.contact.profilePhoto}")
                holder.intialsView.avatarInitials = null
            },
            onStart = {
                logi("## loading contact profile picture for ${favourite.displayName}: ${favourite.contact.profilePhoto}")
            }, onComplete = {
                logi("## oncomplete ${favourite.contact.profilePhoto}")
            }, onError = { _, _ ->
                logi("## error getting profile picture ${favourite.contact.profilePhoto}")
                holder.intialsView.avatarInitials = favourite.displayName.extractInitials()
            })

The first time it runs it outputs this:

2022-02-24 22:22:41.920 8701-8701/com.myapp I/FavouritesAdapter: ############## onBindViewHolder for User1 
2022-02-24 22:22:41.925 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User1: https://placekitten.com/200/200
2022-02-24 22:22:41.925 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:41.927 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User1: https://placekitten.com/200/200
2022-02-24 22:22:41.937 8701-8701/com.myapp I/FavouritesAdapter: ############## onBindViewHolder for User2
2022-02-24 22:22:41.938 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User2: https://placekitten.com/200/200
2022-02-24 22:22:41.939 8701-8701/com.com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:41.940 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User2: https://placekitten.com/200/200
2022-02-24 22:22:41.992 8701-8813/com.myapp I/Builder: ## Loading image from : https://placekitten.com/200/200
2022-02-24 22:22:41.993 8701-8868/com.myapp I/Builder: ## Loading image from : https://placekitten.com/200/200
2022-02-24 22:22:42.180 8701-8701/com.myapp I/FavouritesAdapter: ###### onsuccess https://placekitten.com/200/200
2022-02-24 22:22:42.181 8701-8701/com.myapp I/FavouritesAdapter: ###### onsuccess https://placekitten.com/200/200
2022-02-24 22:22:42.298 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:42.298 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200

The Loading image from... statements are from the ImageLoader requestInterceptor

Then, a bit later when reloading the data it outputs this:

2022-02-24 22:22:47.306 8701-8701/com.myapp I/FavouritesAdapter: ############## onBindViewHolder for User1
2022-02-24 22:22:47.308 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User1 https://placekitten.com/200/200
2022-02-24 22:22:47.309 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:47.311 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User1: https://placekitten.com/200/200
2022-02-24 22:22:47.312 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:47.325 8701-8701/com.myapp I/FavouritesAdapter: ############## onBindViewHolder for User2
2022-02-24 22:22:47.327 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User2: https://placekitten.com/200/200
2022-02-24 22:22:47.328 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200
2022-02-24 22:22:47.330 8701-8701/com.myapp I/FavouritesAdapter: ## loading contact profile picture for User2: https://placekitten.com/200/200
2022-02-24 22:22:47.330 8701-8701/com.myapp I/FavouritesAdapter: ## oncomplete https://placekitten.com/200/200

The weird behavior I'm seeing is this:

Am I misunderstanding the api or could this be a bug? I expected each call to loadImage to result in only one call to onStart and one call to onComplete/onSuccess and the images to be displayed after onComplete.

I'm using io.getstream:avatarview-coil:1.0.3

skydoves commented 2 years ago

Hi @vbsteven, Thank you for reporting this issue with a very detailed explanation!

I just checked a few things about your reports below.

Thanks!

Teju068 commented 2 years ago

I am also facing the same issue, Still not resolved. tried same as your approach

ShivaniWani commented 1 year ago

I am also facing the same issue. It is still not resolved. I was using io.getstream:avatarview-coil:1.0.3 then I updated the version to io.getstream:avatarview-coil:1.0.4 now but issue is same.

Teju068 commented 1 year ago

Hi @ShivaniWani I fixed with one hacky Solution for now First set the initials="" then set the new Image url it works