Created
August 27, 2016 13:53
-
-
Save MostafaAnter/718553ffce21bf5a26dffecc4c058ee3 to your computer and use it in GitHub Desktop.
دى اول خطوه هتجيب كل الجروب بتاعة المستخدم
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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