Sunday, 9 June 2019

How to make reactive item inside RecyclerView?

Let's say that we want to list all the downloading files with progress (this is just a sample to show the problem).

Each item could be represented by this simple class:

data class DownloadingFileItem(val url: String, val progress: Int)

Now as you can see progress is a constant value. Whenever the download progress has been changed, we would have to reload our RecyclerView or at least one particular ViewHolder that represent our item. Of course this would be quite easy task with notifyItemChanged() or DiffUtil, but let's make problem more complicated and assume that rebinding may produce some unwanted view changes (like stopping started animation, etc.) or changes are very frequent. So the only solution would be to make our item more reactive and change constant progress to LiveData or Observable object. But how to achieve that?



from How to make reactive item inside RecyclerView?

No comments:

Post a Comment