use of com.example.singhkshitiz.letschat.RequestAdapter in project Lets-Chat by kshitiz1007.
the class RequestFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
mMainView = inflater.inflate(R.layout.fragment_request, container, false);
mReqList = (RecyclerView) mMainView.findViewById(R.id.recyclerViewRequestList);
mAuth = FirebaseAuth.getInstance();
mCurrent_user_id = mAuth.getCurrentUser().getUid();
mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("friend_request");
mDatabaseReference.keepSynced(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
mReqList.setHasFixedSize(true);
mReqList.setLayoutManager(linearLayoutManager);
requestList.clear();
mRequestAdapter = new RequestAdapter(requestList);
mReqList.setAdapter(mRequestAdapter);
mDatabaseReference.child(mCurrent_user_id).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String userId = dataSnapshot.getKey();
requestList.add(userId);
mRequestAdapter.notifyDataSetChanged();
}
@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) {
}
});
return mMainView;
}
Aggregations