Search in sources :

Example 1 with FirebaseRecyclerAdapter

use of com.firebase.ui.database.FirebaseRecyclerAdapter in project Grupp by tmoronta1208.

the class UserSearchActivity method searchUser.

private void searchUser(String query) {
    Query userSearchQuery;
    if (query.contains("@")) {
        userSearchQuery = searchUserRef.orderByChild("email").startAt(query).endAt(query + "\uf8ff");
    } else {
        userSearchQuery = searchUserRef.orderByChild("first_name").startAt(query).endAt(query + "\uf8ff");
    }
    FirebaseRecyclerAdapter<PublicUser, UserSearchViewHolder> contactsListAdapter = new FirebaseRecyclerAdapter<PublicUser, UserSearchViewHolder>(PublicUser.class, R.layout.add_contact_itemview, UserSearchViewHolder.class, userSearchQuery) {

        @Override
        protected void populateViewHolder(final UserSearchViewHolder viewHolder, final PublicUser model, int position) {
            final String contactID = getRef(position).getKey();
            final String email = model.getEmail();
            final String first = model.getFirst_name();
            final String last = model.getLast_name();
            final String icon = model.getUser_icon().getIcon_url();
            final String zipCode = model.getZip_code();
            // final int radius = model.getRadius();
            viewHolder.setEmail(email);
            viewHolder.setFullName(first, last);
            viewHolder.setIcon(icon);
            viewHolder.addContactButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String radiusString = "20";
                    addToContactList(contactID, viewHolder.addContactButton, first, last, email, icon, radiusString, zipCode);
                }
            });
        }
    };
    searchContactsRecyclerView.setAdapter(contactsListAdapter);
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) Query(com.google.firebase.database.Query) FirebaseRecyclerAdapter(com.firebase.ui.database.FirebaseRecyclerAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with FirebaseRecyclerAdapter

use of com.firebase.ui.database.FirebaseRecyclerAdapter in project Lets-Chat by kshitiz1007.

the class ChatFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // ---ADDING THE RECYCLERVIEW TO FIREBASE DATABASE DIRECTLY----
    // --ORDERING THE MESSAGE BY TIME----
    Query conversationQuery = mConvDatabase.orderByChild("time_stamp");
    FirebaseRecyclerAdapter<Conv, ConvViewHolder> friendsConvAdapter = new FirebaseRecyclerAdapter<Conv, ConvViewHolder>(// --CLASS FETCHED FROM DATABASE-- LAYOUT OF THE SINGLE ITEM--- HOLDER CLASS(DEFINED BELOW)---QUERY
    Conv.class, R.layout.recycle_list_single_user, ConvViewHolder.class, conversationQuery) {

        // ---- GETTING DATA FROM DATABSE AND ADDING TO VIEWHOLDER-----
        @Override
        protected void populateViewHolder(final ConvViewHolder convViewHolder, final Conv conv, int position) {
            final String list_user_id = getRef(position).getKey();
            Query lastMessageQuery = mMessageDatabase.child(list_user_id).limitToLast(1);
            // ---IT WORKS WHENEVER CHILD OF mMessageDatabase IS CHANGED---
            lastMessageQuery.addChildEventListener(new ChildEventListener() {

                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    String data = dataSnapshot.child("message").getValue().toString();
                    convViewHolder.setMessage(data, conv.isSeen());
                }

                @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) {
                }
            });
            // ---ADDING NAME , IMAGE, ONLINE FEATURE , AND OPENING CHAT ACTIVITY ON CLICK----
            mUsersDatabase.child(list_user_id).addValueEventListener(new ValueEventListener() {

                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    final String userName = dataSnapshot.child("name").getValue().toString();
                    String userThumb = dataSnapshot.child("thumb_image").getValue().toString();
                    if (dataSnapshot.hasChild("online")) {
                        String userOnline = dataSnapshot.child("online").getValue().toString();
                        convViewHolder.setUserOnline(userOnline);
                    }
                    convViewHolder.setName(userName);
                    convViewHolder.setUserImage(userThumb, getContext());
                    // --OPENING CHAT ACTIVITY FOR CLICKED USER----
                    convViewHolder.mView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent chatIntent = new Intent(getContext(), ChatActivity.class);
                            chatIntent.putExtra("user_id", list_user_id);
                            chatIntent.putExtra("user_name", userName);
                            startActivity(chatIntent);
                        }
                    });
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });
        }
    };
    mConvList.setAdapter(friendsConvAdapter);
}
Also used : Query(com.google.firebase.database.Query) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DatabaseError(com.google.firebase.database.DatabaseError) Conv(com.example.singhkshitiz.letschat.Conv) FirebaseRecyclerAdapter(com.firebase.ui.database.FirebaseRecyclerAdapter) ValueEventListener(com.google.firebase.database.ValueEventListener) ChildEventListener(com.google.firebase.database.ChildEventListener)

Example 3 with FirebaseRecyclerAdapter

use of com.firebase.ui.database.FirebaseRecyclerAdapter in project Lets-Chat by kshitiz1007.

the class UserActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    // String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
    // mUsersDatabaseReference.child(uid).child("online").setValue("true");
    // -------FIREBASE RECYCLE VIEW ADAPTER-------
    FirebaseRecyclerAdapter<Users, UserViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UserViewHolder>(Users.class, R.layout.recycle_list_single_user, UserViewHolder.class, mUsersDatabaseReference) {

        @Override
        protected void populateViewHolder(UserViewHolder viewHolder, Users users, int position) {
            viewHolder.setName(users.getName());
            viewHolder.setStatus(users.getStatus());
            viewHolder.setImage(users.getThumbImage(), getApplicationContext());
            final String user_id = getRef(position).getKey();
            viewHolder.mView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent profileIntent = new Intent(UserActivity.this, ProfileActivity.class);
                    profileIntent.putExtra("user_id", user_id);
                    startActivity(profileIntent);
                }
            });
        }
    };
    mUsersList.setAdapter(firebaseRecyclerAdapter);
}
Also used : FirebaseRecyclerAdapter(com.firebase.ui.database.FirebaseRecyclerAdapter) Intent(android.content.Intent) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 4 with FirebaseRecyclerAdapter

use of com.firebase.ui.database.FirebaseRecyclerAdapter in project Lets-Chat by kshitiz1007.

the class FriendFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    // ---FETCHING DATABASE FROM mFriendDatabase USING Friends.class AND ADDING TO RECYCLERVIEW----
    FirebaseRecyclerAdapter<Friends, FriendsViewHolder> friendsRecycleAdapter = new FirebaseRecyclerAdapter<Friends, FriendsViewHolder>(Friends.class, R.layout.recycle_list_single_user, FriendsViewHolder.class, mFriendDatabase) {

        @Override
        protected void populateViewHolder(final FriendsViewHolder friendViewHolder, Friends friends, int position) {
            friendViewHolder.setDate(friends.getDate());
            final String list_user_id = getRef(position).getKey();
            mUsersDatabase.child(list_user_id).addValueEventListener(new ValueEventListener() {

                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    // ---IT WORKS WHENEVER CHILD OF mMessageDatabase IS CHANGED---
                    final String userName = dataSnapshot.child("name").getValue().toString();
                    String userthumbImage = dataSnapshot.child("thumb_image").getValue().toString();
                    if (dataSnapshot.hasChild("online")) {
                        String userOnline = dataSnapshot.child("online").getValue().toString();
                        friendViewHolder.setOnline(userOnline);
                    }
                    friendViewHolder.setName(userName);
                    friendViewHolder.setUserImage(userthumbImage, getContext());
                    // --ALERT DIALOG FOR OPEN PROFILE OR SEND MESSAGE----
                    friendViewHolder.mView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            CharSequence[] options = new CharSequence[] { "Open Profile", "Send Message" };
                            AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
                            builder.setTitle("Select Options");
                            builder.setItems(options, new AlertDialog.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                        Intent intent = new Intent(getContext(), ProfileActivity.class);
                                        intent.putExtra("user_id", list_user_id);
                                        startActivity(intent);
                                    }
                                    if (which == 1) {
                                        Intent intent = new Intent(getContext(), ChatActivity.class);
                                        intent.putExtra("user_id", list_user_id);
                                        intent.putExtra("user_name", userName);
                                        startActivity(intent);
                                    }
                                }
                            });
                            builder.show();
                        }
                    });
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                }
            });
        }
    };
    mFriendsList.setAdapter(friendsRecycleAdapter);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ProfileActivity(com.example.singhkshitiz.letschat.ProfileActivity) ChatActivity(com.example.singhkshitiz.letschat.ChatActivity) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) DatabaseError(com.google.firebase.database.DatabaseError) FirebaseRecyclerAdapter(com.firebase.ui.database.FirebaseRecyclerAdapter) ValueEventListener(com.google.firebase.database.ValueEventListener)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)4 View (android.view.View)4 FirebaseRecyclerAdapter (com.firebase.ui.database.FirebaseRecyclerAdapter)4 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)3 ImageView (android.widget.ImageView)2 DataSnapshot (com.google.firebase.database.DataSnapshot)2 DatabaseError (com.google.firebase.database.DatabaseError)2 Query (com.google.firebase.database.Query)2 ValueEventListener (com.google.firebase.database.ValueEventListener)2 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 PublicUser (com.example.c4q.capstone.database.publicuserdata.PublicUser)1 ChatActivity (com.example.singhkshitiz.letschat.ChatActivity)1 Conv (com.example.singhkshitiz.letschat.Conv)1 ProfileActivity (com.example.singhkshitiz.letschat.ProfileActivity)1 ChildEventListener (com.google.firebase.database.ChildEventListener)1