RxFirebaseRecyclerAdapter get key for value
abhishekBansal opened this issue · 1 comments
How can I get key for particular item in RxFirebaseRecyclerAdapter?
For uses cases like when I click on some item I need to update something in firebase database.
Like if you use a normal RecyclerView
you should save the ID of your item always in your DataModel
for the application. That's one of the points to keep the FirebaseModel different than your applicationModel.
Example:
data class FirebaseComment(val postId: String = "",
val postAuthorId: String = "",
val postTitle: String = "",
val author: FirebaseUserData = FirebaseUserData(),
val comment: String = "",
@ServerTimestamp val timestamp: Date? = null)
data class Comment(val uid: String,
val postAuthorId: String,
val postId: String,
val author: UserData,
val comment: String,
val timestamp: Date)
In that way you will keep the ID's in your model without save them on the database, just be care to have a custom method for the cast from one to another one were you will retrieve the ID
from the DataSnapshot and add it to your appModel.
Finally, if this solution is not the best for you, I encorage you to made changes on the FirebaseRecyclerAdapter and feel free to upload a PR 👍
Have a nice day!