vitorhugods/AvatarView

Use avatarview in recyclerview

frfmmdreza opened this issue · 1 comments

Hi, actually i don't want to report an issue, i want some help if it is possible for you.
Im using avatarview in a recyclerviee. When user click on avatar i get some data from the server, i do this in my activity (not adapter), now the problem is that how can i stop avatar animation when i get the data? Because i get data inside my activity and i cant stop avatar animation from activity.
Thank you

Ok.

That's an implementation issue, mostly related to the application architecture. I'll try to help nevertheless.

You have a few options.

One of them, the most simple, probably (I didn't see a single piece of your code):
The activity calls:

//When the loading starts
item.isLoading = true
adapter.notifyItemChanged(itemIndex)
startLoading()

//When the loading is complete
item.isLoading = false
adapter.notifyItemChanged(itemIndex)

And in your ViewHolder, to manage such information.

public fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
        val item = data[position]
        holder.avatarView.isAnimating = item.isLoading
}

I don't think that the Activity should be the one responsible for the connection in the first place. Maybe you should learn a bit more about architecture patterns, such as MVVM.