mk-5 / gdx-fireapp

libGDX Firebase API
Apache License 2.0
63 stars 21 forks source link

DataSnapshot implementation #59

Closed wangdong20 closed 2 years ago

wangdong20 commented 2 years ago

Is your feature request related to a problem? Please describe. When I try to observe child change with child event added, I want to get access to the DataSnapshot to access the key, value and child in Database reference.

Describe the solution you'd like Please implement DataSnapshot when observe Database reference child change event like DataSnapshot, or tell me how to use it if you already implement it. Thanks.

mk-5 commented 2 years ago

@wangdong20 could you give me some code/pseudo code example? I'm not sure if I got it right

wangdong20 commented 2 years ago

Sure. This is what I want to implemented with gdx-fireapp API. ref.inReference("users/${it.userInfo.uid}").onChildChange(DataSnapshot::class.java, ChildEventType.ADDED)

This is how the iOS official implemented for what I want. self.ref!.child("users/\(user.uid)").observe(.childAdded, with: {snapshot in if snapshot.key == "GameId" {// TODO}

I already implement it in iOS but not in libgdx, that's why I am here.

mk-5 commented 2 years ago

@wangdong20 onChildEvent is already covered:

Example:

GdxFIRDatabase.inst()
    .inReference("/employees")
    .onChildChange(List.class, ChildEventType.ADDED)
wangdong20 commented 2 years ago

@wangdong20 onChildEvent is already covered:

Example:

GdxFIRDatabase.inst()
    .inReference("/employees")
    .onChildChange(List.class, ChildEventType.ADDED)

I know onChildEvent is covered. My question is there a way to implement DataSnapshot as the data type to access child change under current child in database.

For instance, a table like this: user/fdhsi3232 /"gameId":"483hujkds" /"status":"placeholder" the data reference path is "user/fdhsi3232" When the child added event fired, can I access the DataSnapshot under current reference? So I can access the data under current path like this: if snapshot.key == "gameId" { var gameId = snapshot.value} else if snapshot.key == "status" {var status = snapshot.value}

I know you already implement it by extracting data as List class, but if the key-value data under current reference is not the same, how can you put them all in the List. So I think the best way is implementing DataSnapshot like access the tree structure under current reference, then I can access any value with the given key. What do you think?

mk-5 commented 2 years ago

@wangdong20 could you give me some psuedo-code proposition, how it should look. You can modify the example code snipper from your previous comment

wangdong20 commented 2 years ago

I already use official Firebase realtime database in libgdx. I can implement interface in android launcher as a bridge between core and android module. The Firebase realtime database framewrok is very large, I don't think it will be good to rewrite firebase database framework and interface in this repo. I will use official framework. If I were you, I will abandon this repo.

mk-5 commented 2 years ago

Re-write of the whole Firebase realtime database framework is not a goal of that library. It's handy for some cases of course as any library :) If you are not using multiple platforms, but only Android - using the official sdk directly probably make sense as well.