mk-5 / gdx-fireapp

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

Support for goOffline, onDisconnect().setValue() in core and Android #56

Closed wangdong20 closed 2 years ago

wangdong20 commented 2 years ago

Is your feature request related to a problem? Please describe. I am glad to find this library to support Firebase realtime database in libgdx. You are life saver. I try to implement DatabaseReference.goOffline() and goOnline to manually connect database or disconnect but I couldn't find that API. I also cannot find DatabaseReference.onDisconnect() to set value or remove value in database when disconnect the database. Those are important features in my project. Hope it will be implemented. Or tell me how to implement it in this library under current version.

Describe the solution you'd like goOnline(), goOffline(), onDisconnect().setValue(value), onDisconnect().removeValue() I would like you can add those APIs I mentioned above.

mk-5 commented 2 years ago

Hello @wangdong20 ! good to hear :)

There is an existing API to listen on connection change. Example:

        GdxFIRDatabase.inst()
                .onConnect()
                .after(GdxFIRAuth.inst().signInAnonymously())
                .then(new Consumer<ConnectionStatus>() {
                    @Override
                    public void accept(ConnectionStatus connectionStatus) {
                        if (connectionStatus == ConnectionStatus.CONNECTED) {
                            // connection done! 
                        }
                    }
                });

is it something you are looking for?

wangdong20 commented 2 years ago

It would be better to implement DatabaseReference.onDisconnect().setValue or remove value API for me. Is there also goOffline, goOnline API to disconnect or connect the database manually? Like this APi page [API](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/database/DatabaseReference#goOffline())

mk-5 commented 2 years ago

@wangdong20 👍 make sense. I will look on that

mk-5 commented 2 years ago

@wangdong20 sorry for huge delay. I didn't have so many free hours to take some gdx-fireapp topics.

but 🥁🥁🥁🥁🥁 good news 🥳 the feature is almost there. It should be release today/tomorrow.

There will be a support for methods:

onDisconnect().removeValue() onDisconnect().setValue(object) onDisconnect().cancel() .goOnline() .goOffline()

mk-5 commented 2 years ago

@wangdong20 pls check version 3.3.0. I've added a few exampels in WIKI