Search in sources :

Example 1 with PublicUserDetails

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) {
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) HashMap(java.util.HashMap) DatabaseReference(com.google.firebase.database.DatabaseReference) PublicUserDetails(com.example.c4q.capstone.database.publicuserdata.PublicUserDetails) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

PublicUserDetails (com.example.c4q.capstone.database.publicuserdata.PublicUserDetails)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1 HashMap (java.util.HashMap)1