I have successfully implemented geoFire to get the keys of entries from a main firebase node within the user's area.
I have then attempted to store those keys in a new, unique node, in order to use them later to populate a viewHolder, as this seems to be best practice.
The problem is that I don't want all of the objects stored in the unique node to actually populate the viewHolder; I only want a subset of them.
If I filter inside the populateViewHolder method, e.g.,
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
SwarmReport retrievedModel = dataSnapshot.getValue(SwarmReport.class);
if(!retrievedModel.isClaimed()){
viewHolder.bindSwarmReport(retrievedModel);
}
}
I get some items in the viewHolder that are blank.
If, instead, I try to filter before setting up the FirebaseAdapter, e.g. in my addGeoQueryEventListener methods, I have to add an addListenerForSingleValueEvent to check the criteria by which I aim to filter:
public void onKeyEntered(String key, GeoLocation location) {
claimCheckKey = key;
final DatabaseReference claimCheckRef = FirebaseDatabase.getInstance().getReference("all").child(key);
claimCheckRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
SwarmReport claimCheckSwarmReport = dataSnapshot.getValue(SwarmReport.class);
if (!claimCheckSwarmReport.isClaimed()){
swarmReportIds.add(claimCheckKey);
}
}
It seems that onGeoQueryReady executes before addListenerForSingleValueEvent in onKeyEntered is finished. Any recommendations on how to get onGeoQueryReady to wait for all of the swarmReportIds.add(claimCheckKey)s to complete?
In case it's helpful, here's a snapshot of my firebase structure:

I don't really understand what you are trying to achieve but I will take a guess and say that you want not only the closest
keybut you also want to filter the closestkeybased on some other criteria, e.g., closest restaurant then prices,The workaround I did to achieve this, (still looking for better options) is to set a flag inside the
onDatachangemethod that I called on inside theonKeyenteredmethod, that compares entries inside that node, (for sake of argument we will say prices)UPDATE
And outside the for each loop of
onDataChangeI set to execute the function that populates thearraylistof myadapteronly when the function is truegetRestaurants method
Another suggestion would be to make a function on the cloud, (assuming again) in your case that all you need is to monitor whether the value of "claimed" changes, so you can set an
onUpdateevent trigger or andonWriteand check the value inonChanged()and get the current value (true/false)after that you can make use of geoFire queries and get the close by users and update their nodes depending on the value.Event Triggers
Cloud Functions