use of com.example.c4q.capstone.database.publicuserdata.PublicUserDetails in project Grupp by tmoronta1208.
the class UserSearchActivity method addToContactList.
public void addToContactList(String contactID, final Button addContactButton, String first, String last, String email, String url, String radius, String zipcode) {
/**
* TODO: Write logic to retrieve contacts list first, and then update the list with the new values.
* TODO: also need to write logic to check if user is already in contact list
*/
final PublicUserDetails publicUserDetails = new PublicUserDetails(first, last, email, url, contactID, radius, zipcode);
final Map<String, Object> user_contacts = new HashMap<>();
final DatabaseReference userContactsRef = rootRef.child(USER_CONTACTS).child(currentUserID);
userContactsRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
PublicUserDetails pubUser = ds.getValue(PublicUserDetails.class);
if (pubUser != null) {
String userId = pubUser.getUid();
user_contacts.put(userId, pubUser);
}
}
String currentUID = publicUserDetails.getUid();
user_contacts.put(currentUID, publicUserDetails);
userContactsRef.updateChildren(user_contacts);
addContactButton.setVisibility(View.INVISIBLE);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Aggregations