Search code examples
androidfirebasefirebase-realtime-databasefirebaseui

FirebaseRecyclerAdapter still showing all items. Should not show any


I want FirebaseRecyclerAdapter to check if there invites ending with email address, and show uids. Somehow it output all data, as if there were no filtering and ordering.

Here is json data.

"invites" : {
  "4u60kmvvO9TwzBrLpP5SG4ICU9r1_test5%2E@test%2Etest" : {
    "cost" : "2",
  },
  "4u60kmvvO9TwzBrLpP5SG4ICU9r1_test4@test%2Etest" : {
    "costs" : "0"
  },
  "UQW5VEAojMOyB2WGTU9aTPUBepg1_test6%2E@test%2Etest" : {
    "costs" : "0"      
  }
}

I want to set FirebaseRecyclerAdapter. Here is adapter.

 mAdapter = new FirebaseRecyclerAdapter<Event, UserHolder>(
      Event.class, 
      R.layout.layout, 
      UserHolder.class, 
      ref.child("invites").orderByKey().endAt(encodeAsFirebaseKey(email))
 ) {}

Why I'm getting all three items, when I test with test@test.test email? It seems that I've read documentation and it should work. Any ideas?

Update.

 private String encodeAsFirebaseKey(String string) {
    return string.replace(".", "%2E");
}

It returns test@test%2Etest.

     protected void populateViewHolder(final UserHolder viewHolder, Event model, final int position) {
     final String key = this.getRef(position).getKey().split("_")[0];
            viewHolder.setName(key);     
            }

Solution

  • You seems to be confusing how endAt() works. It matches all strings, ending at the one that starts with the argument you pass. It does not match strings ending with the argument you pass.

    So endAt("4u60kmvvO9TwzBrLpP5SG4ICU9r1_test4@test%2Etest") matches:

    "4u60kmvvO9TwzBrLpP5SG4ICU9r1_test5%2E@test%2Etest" : {
      "cost" : "2",
    },
    "4u60kmvvO9TwzBrLpP5SG4ICU9r1_test4@test%2Etest" : {
      "costs" : "0"
    },
    

    But endAt("test@test%2Etest") returns nothing, because no key starts with that.