Search in sources :

Example 1 with RequestAdapter

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;
}
Also used : RequestAdapter(com.example.singhkshitiz.letschat.RequestAdapter) DatabaseError(com.google.firebase.database.DatabaseError) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) ChildEventListener(com.google.firebase.database.ChildEventListener)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RequestAdapter (com.example.singhkshitiz.letschat.RequestAdapter)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1