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);
}
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);
}
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);
}
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);
}
Aggregations