Skip to content

Instantly share code, notes, and snippets.

@MostafaAnter
Created August 27, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MostafaAnter/718553ffce21bf5a26dffecc4c058ee3 to your computer and use it in GitHub Desktop.
Save MostafaAnter/718553ffce21bf5a26dffecc4c058ee3 to your computer and use it in GitHub Desktop.
دى اول خطوه هتجيب كل الجروب بتاعة المستخدم
rivate void fetchUserGroupsAndPutItIntoRecyclerView() {
// delete dataSet if Online
if (mDataset.size() > 0) {
clearDataSet();
}
final String encodedEmail = Utils.encodeEmail(new MAKPrefStore(getActivity()).getPreferenceValue(Constants.PREFERENCE_USER_EMAIL));
final DatabaseReference mainLocation = FirebaseDatabase.getInstance()
.getReferenceFromUrl(Constants.FIREBASE_URL);
mainLocation.child(Constants.FIREBASE_LOCATION_USERS).child(encodedEmail)
.child(Constants.FIREBASE_LOCATION_ROOMS).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue() != null) {
// for each group, fetch the name
final String groupKey = dataSnapshot.getKey();
mainLocation.child(Constants.FIREBASE_LOCATION_ROOMS)
.child(groupKey).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
Groups groups = dataSnapshot.getValue(Groups.class);
groups.setGroupId(groupKey);
Log.d(Constants.LOGTAG, groups.getName());
mDataset.add(groups);
// this solve my problem
mAdapter.notifyItemInserted(mDataset.size()-1);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment