Search in sources :

Example 1 with ChangeEventListenerBase

use of com.supercilex.robotscouter.util.DatabaseHelper.ChangeEventListenerBase in project Robot-Scouter by SUPERCILEX.

the class AppIndexingService method onDataChange.

@Override
public void onDataChange(DataSnapshot snapshot) {
    long numOfExpectedTeams = snapshot.getChildrenCount();
    if (numOfExpectedTeams == 0) {
        FirebaseAppIndex.getInstance().update();
        return;
    }
    Constants.sFirebaseTeams.addChangeEventListener(new ChangeEventListenerBase() {

        @Override
        public void onChildChanged(EventType type, DataSnapshot snapshot, int index, int oldIndex) {
            if (type == EventType.ADDED) {
                mIndexables.add(Constants.sFirebaseTeams.getObject(index).getHelper().getIndexable());
            }
            if (mIndexables.size() >= numOfExpectedTeams) {
                FirebaseAppIndex.getInstance().update(mIndexables.toArray(new Indexable[mIndexables.size()]));
                Constants.sFirebaseTeams.removeChangeEventListener(this);
            }
        }
    });
}
Also used : ChangeEventListenerBase(com.supercilex.robotscouter.util.DatabaseHelper.ChangeEventListenerBase) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

DataSnapshot (com.google.firebase.database.DataSnapshot)1 ChangeEventListenerBase (com.supercilex.robotscouter.util.DatabaseHelper.ChangeEventListenerBase)1