Giter VIP home page Giter VIP logo

Comments (7)

thorbenprimke avatar thorbenprimke commented on June 28, 2024

@kmare - Yes, it should update but because I'm only diffing on the item's id (primary key) which I'm assuming remains the same in your case and thus the notifyItemChanged is not triggered.

If you have automatic updates enabled, then whenever the Realm changes the update is received by the adapter. In order to filter out updates not related to the Realm in the adapter, I'm using the ids to detect change and trigger the animations.
I need to see about an efficient way to detect the change when an item's id is the same but the contents are changed. Maybe hashCode could help.

from realm-recyclerview.

thorbenprimke avatar thorbenprimke commented on June 28, 2024

Committed 49a7a34

from realm-recyclerview.

thorbenprimke avatar thorbenprimke commented on June 28, 2024

@kmare - I added a new optional parameter to the adapter to specify a columnName that should be used for the "id" that is used for diffing the realm changes.
I tried hashCode but that didn't work because the hashCode didn't change when making an update to a Realm object. It also cannot be overriden to have a custom hashCode.

I updated the LinearLayout example so that if you long press a row, it updates the text and this triggers the automatic update and notifyItemChanged for that item.

from realm-recyclerview.

kmare avatar kmare commented on June 28, 2024

Hi @thorbenprimke , thank you for working on this. I implemented what you said, but I think it's not the right way to do it (I might be totally wrong of course and didn't understand exactly what to do). I'll try to explain using your example: so if set the "quote" column to the adapter, it works. But that means that if I have more fields in my model that might change, the notifyItemChanged() won't be called on them. So I believe what's needed to be set in the adapter is actually the "id" (PrimaryKey) which remains constant and any change made to any other field should trigger the notifyItemChanged().
Not sure I explained properly the issue.

from realm-recyclerview.

thorbenprimke avatar thorbenprimke commented on June 28, 2024

Yes, you should ideally have a column that would change whenever anything on the object changes.

Since posting my last response, I actually changed it back to always use the primaryKey and have an optional second column (202b590).
In the example, I'm using "quote" for the optional column.

However, in a real application, it probably should be something like "lastChangedTime". This way it is guaranteed that the row changed is detected.

I hope this clears up any confusion. The whole "keeping track of the ids" is simply to work around the fact that the realm change notifications don't include any information on what has changed. Once this is fixed / added, the "ids" and "diff code" can be removed.

from realm-recyclerview.

kmare avatar kmare commented on June 28, 2024

You're totally right, didn't realize the adapter parameter was about the second optional column (seemed weird at first, I should have looked at the code a bit more).
Thank you!

from realm-recyclerview.

thorbenprimke avatar thorbenprimke commented on June 28, 2024

No, worries. Thanks for raising this issue initially.

from realm-recyclerview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.