FlexibleAdapter icon indicating copy to clipboard operation
FlexibleAdapter copied to clipboard

FlexibleAdapter#updateDataSet should not take a list of IFlexible as argument

Open christophehenry opened this issue 7 years ago • 4 comments

This forces to wrap every element of the list to an IFlexible before updating the adapter. In case of managing data through Jetpack's Room/LiveData, the dev has no control on the data when refreshed, and is just notified with the whole list when an element is refreshed which forces to rewrap every element of the list. I'm concern this could cause memory leaks and performance problems on the long run or with huge data sets.

Instead, I propose it takes the data list as is along with a factory to wrap only the new items.

christophehenry avatar Apr 09 '19 09:04 christophehenry

@christophehenry, with LiveData and Room everything changed for the adapter. Those callbacks return always the whole list and maybe another solution has to be implemented. As you suggests, I tried something similar in the LiveData addOn library, but then I didn't have to continue. Your suggestions is to accept 2 params: the list and the factory, but where the difference has to be done and comparing which objects?

davideas avatar May 08 '19 14:05 davideas

Your suggestions is to accept 2 params: the list and the factory, but where the difference has to be done and comparing which objects?

Since your library emphasize on the importance of overriding equals and hashCode. I suppose every IFexible should have the same equals and hashCode than its embedding item. Am I right?

christophehenry avatar May 13 '19 11:05 christophehenry

Ok, I thought about it. Regarding the factory: I can accept a custom Factory class or predefined Factory where maybe I can even accept a generic Class type with extra params to configure the IFlexible object, however this object might be a wrapper type holder, like "IHolder". Needs some experiments and the time to do it... :-)

davideas avatar May 13 '19 11:05 davideas

I suppose adding a simple functionnal interface of type:

IHolder<? extends T> create(T item)

as a third parameter should be sufficent. Plus, it has the advantage of being fully compatible with Kotlin's lambda.

christophehenry avatar May 13 '19 12:05 christophehenry