I have the following structure within my firebase realtime database:
- artists
- ArtistID
- name
- listOfPaintings
- PaintingID1
- PaintingID2
- ArtistID
- paintings (there can be
- PaintingID1
- copies
- price
- PaintingID2
- copies
- price
- ...
- PaintingIDX
- copies
- price
- PaintingID1
Now I want to listen for changes of specific paintingIDs and specific ArtistIDs. For example I want to listen to PaintingID1, PaintingID6, PaintingID7, PaintingID11.
My repository code so far:
override fun observeThisPainting(painting: Painting, receiveDataFromBackendCallback: DataFromBackendCallback<Painting>) {
this.receiveDataFromBackendCallback = receiveDataFromBackendCallback
val myRef = database.child("paintings").child(painting.paintingId)
myRef.addValueEventListener(this)
}
override fun onDataChange(snapshot: DataSnapshot) {
val painting = snapshot.getValue(Painting::class.java)
painting?.let { receiveDataFromBackendCallback.onSuccess(it) }
}
override fun onCancelled(error: DatabaseError) {
}
- Is the architecture of my RTDBs right? In my first attempt I saved all paintings inside the artist listOfPaintings. Now I only save the keys for them there.
- How can I achieve to listen to a subset of objects of a specific node from my viewmodel? (I know how to listen to all items of the paintings node, but I want to know if there is a way to listen to speficic items of this node)
Thanks for your ideas!