Search in sources :

Example 1 with FeedMessage

use of com.google.samples.apps.iosched.feed.data.FeedMessage in project iosched by google.

the class FeedPresenter method initializeDataListener.

@Override
public void initializeDataListener(DatabaseReference databaseReference) {
    if (mEventListener == null) {
        mEventListener = new ChildEventListener() {

            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                try {
                    FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
                    mView.addFeedMessage(feedMessage);
                } catch (DatabaseException e) {
                    mView.showErrorMessage();
                    LOGE(TAG, "Firebase error - " + e);
                }
            }

            @Override
            public void onChildChanged(DataSnapshot dataSnapshot, String s) {
                try {
                    FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
                    mView.updateFeedMessage(feedMessage);
                } catch (DatabaseException e) {
                    mView.showErrorMessage();
                    LOGE(TAG, "Firebase error - " + e);
                }
            }

            @Override
            public void onChildRemoved(DataSnapshot dataSnapshot) {
                try {
                    FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
                    mView.removeFeedMessage(feedMessage);
                } catch (DatabaseException e) {
                    mView.showErrorMessage();
                    LOGE(TAG, "Firebase error - " + e);
                }
            }

            @Override
            public void onChildMoved(DataSnapshot dataSnapshot, String s) {
                try {
                    FeedMessage feedMessage = dataSnapshot.getValue(FeedMessage.class);
                    mView.updateFeedMessage(feedMessage);
                } catch (DatabaseException e) {
                    mView.showErrorMessage();
                    LOGE(TAG, "Firebase error - " + e);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                mView.showErrorMessage();
            }
        };
    }
    databaseReference.addChildEventListener(mEventListener);
}
Also used : FeedMessage(com.google.samples.apps.iosched.feed.data.FeedMessage) DatabaseError(com.google.firebase.database.DatabaseError) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseException(com.google.firebase.database.DatabaseException) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

ChildEventListener (com.google.firebase.database.ChildEventListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 DatabaseException (com.google.firebase.database.DatabaseException)1 FeedMessage (com.google.samples.apps.iosched.feed.data.FeedMessage)1