-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
From https://github.com/realm/realm-android-adapters/issues/21#issuecomment-285349284
RecyclerView animations have support for partial updates (payloads). This requires that our Finegrained Collection Notifications can provide individual Object Changesets for each individual object instead of just the index changed.
Support for object notifications will be implemented in #4101, and quite possible we could leverage that to provide payloads to the collection notifications.
It is unclear how expensive calculating the diff for each object in a big query result would be, but a hunch would be very. , so it is a bit unclear how the API could look like.
Some ideas below. Any others?
Option A: Automatically calculated as part of the standard Changeset
public interface OrderedCollectionChangeSet() { // ... old methods // Return changeset for the given index in the new array. ObjectChangeset getChangePayload(long index); } // Usage RealmResults<Person> persons = realm.where(Person.class).findAll(); persons.addChangeListener(new OrderedRealmCollectionChangeListener() { @Override public void onChange(RealmResults<Person> persons, OrderedCollectionChangeSet changeset) { for (int index : changeset.getChanges()) { adapter.notifyItemChanged(index, changeset.getChangePayload(index)); } } });
- Advantage: Easy to use for developers and only require one smal change to a public interface
- Disadvantage: Always calculating the object diff might be very expensive. I don't think we can lazily evaluate it, but we could probably keep the result on the C++ side until needed in Java.
Option B: Parameter to addChangeListener
// Same change to OrderedCollectionChangeSet // Usage RealmResults<Person> persons = realm.where(Person.class).findAll(); boolean calculatePayload = true; persons.addChangeListener(new OrderedRealmCollectionChangeListener() { @Override public void onChange(RealmResults<Person> persons, OrderedCollectionChangeSet changeset) { for (int index : changeset.getChanges()) { adapter.notifyItemChanged(index, changeset.getChangePayload(index)); } } }, calculatePayload);
- Slightly more annoying setup, but object diff only calculated if specifically required.
TODO
- [ ] Design exact API
- [ ] Blocked by Single Object Notifications #4101
- [ ] Blocked by Object Store needing to support this