thorbenprimke / realm-recyclerview

A RecyclerView that is powered by Realm and lots more
555 stars 151 forks source link

Fix issue when RealmResults is sorted on the same column as animateExtraColumnName. #81

Closed long-greg-c closed 5 years ago

long-greg-c commented 8 years ago

Using animateExtraColumnName and having the RealmResults is sorted by the same column as animateExtraColumnName, there is the potential for a single row to have a change in animateExtraColumnName that will also change its row position.

If this occurs then the diff delta will be a INSERT and DELETE for that row. If the insert is done first then the delete will be on the incorrect row. The result being that the original row will still be visible unchanged, the updated row will have then replaced an unrelated row at the new position.

Example of what can occur.

index primarykey animateExtraColumn
0 abc 100
1 xyz 75
2 123 50
3 ijk 20

Before (RealmResults sorted DESC on animateExtraColumn)

index primarykey animateExtraColumn
0 abc 100
1 123 90
2 123 50
3 ijk 20

After (primary key row 123 has had its animate column incremented to 90)

This pull request re-sorts the delta's to ensure the DELETE takes place before the INSERT.

Documentation is also updated for the use of animateExtraColumnName.

Chesteer89 commented 8 years ago

Good job, sort works fine now!