Search in sources :

Example 11 with PublicUser

use of com.example.c4q.capstone.database.publicuserdata.PublicUser in project Grupp by tmoronta1208.

the class CurrentUserUtility method getCurrentPublicUser.

public void getCurrentPublicUser(final PublicUserListener userListener) {
    ValueEventListener publicUserListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (currentUserExists) {
                PublicUser user = dataSnapshot.child(currentUserID).getValue(PublicUser.class);
                if (user != null) {
                    userHasPublicProfile = true;
                    Log.d(TAG, "getPublicUser with listener: user first name: " + user.getFirst_name());
                    // currentUserListener.getPublicUser(user);
                    userListener.publicUserExists(userHasPublicProfile);
                } else {
                    userHasPublicProfile = false;
                }
                Log.d(TAG, "getPublicUser: user has public profile " + userHasPublicProfile);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            // Getting Post failed, log a message
            Log.d(TAG, "loadPost:onCancelled", databaseError.toException());
        // ...
        }
    };
    publicUserReference.addListenerForSingleValueEvent(publicUserListener);
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 12 with PublicUser

use of com.example.c4q.capstone.database.publicuserdata.PublicUser in project Grupp by tmoronta1208.

the class CurrentUserUtility method getCurrentPublicUser.

/**
 * ajoxe:
 * this method gets current private user (Private user object from db) user from the datatbase
 */
public void getCurrentPublicUser() {
    ValueEventListener publicUserListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (currentUserExists) {
                PublicUser user = dataSnapshot.child(currentUserID).getValue(PublicUser.class);
                if (user != null) {
                    userHasPublicProfile = true;
                    Log.d(TAG, "getPublicUser: user first name: " + user.getFirst_name());
                    currentUserListener.getPublicUser(user);
                } else {
                    userHasPublicProfile = false;
                }
                Log.d(TAG, "getPublicUser: user has public profile " + userHasPublicProfile);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            // Getting Post failed, log a message
            Log.d(TAG, "loadPost:onCancelled", databaseError.toException());
        // ...
        }
    };
    publicUserReference.addListenerForSingleValueEvent(publicUserListener);
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 13 with PublicUser

use of com.example.c4q.capstone.database.publicuserdata.PublicUser in project Grupp by tmoronta1208.

the class ContactListFragment method loadFriendsList.

public void loadFriendsList(List<String> keyList) {
    Log.d("user friends frag", "loadFriendsFrag" + friendKeys.size());
    for (String s : friendKeys) {
        Log.d("Contacts", "loadFriendsFrag: friends key strings: " + s);
        fbUserDataUtility.getPublicUser(s, new FBUserDataListener() {

            @Override
            public void getUid(String userID) {
            }

            @Override
            public void getPublicUser(PublicUser publicUser) {
                friendsUserList.add(publicUser);
                contactListAdapter.notifyDataSetChanged();
                Log.d("CONTACTS", "loadFriendsList: friends name: " + publicUser.getFirst_name());
                Log.d("CONTACTS", "loadFriendsList: public user list size: " + friendsUserList.size());
            }
        });
    }
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) FBUserDataListener(com.example.c4q.capstone.utils.FBUserDataListener)

Example 14 with PublicUser

use of com.example.c4q.capstone.database.publicuserdata.PublicUser in project Grupp by tmoronta1208.

the class EditProfileActivity method saveToDatabase.

private void saveToDatabase() {
    firstNameString = firstName.getText().toString().trim();
    lastNameString = lastName.getText().toString().trim();
    zipCodeString = zipCode.getText().toString();
    if (!firstNameString.equals("") && !lastNameString.equals("") && !zipCodeString.equals("")) {
        publicUser = new PublicUser(currentUserID, firstNameString, lastNameString, zipCodeString, budgetString, currentUserEmail, over18, over21, radius);
        privateUser = new PrivateUser(firstNameString, lastNameString, over18, over21, radius);
        privateUserLocation = new PrivateUserLocation(share_location, lat, lng);
        // will cause a nullPointerException, to be fixed
        userIcon = new UserIcon(iconUrl);
        /**
         * searchUserReference needs to be added at time of account creation
         */
        publicUserReference.child(currentUserID).setValue(publicUser);
        privateUserReference.child(currentUserID).setValue(privateUser);
        userIconReference.child(currentUserID).setValue(userIcon);
        privateUserLocationReference.child(currentUserID).child(PRIVATE_LOCATION).setValue(privateUserLocation);
        startActivity(new Intent(EditProfileActivity.this, UserProfileActivity.class));
    } else {
        firstName.setError("Required");
        lastName.setError("Required");
        zipCode.setError("Required");
    }
}
Also used : PrivateUser(com.example.c4q.capstone.database.privateuserdata.PrivateUser) PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) PrivateUserLocation(com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) Intent(android.content.Intent)

Example 15 with PublicUser

use of com.example.c4q.capstone.database.publicuserdata.PublicUser in project Grupp by tmoronta1208.

the class EditProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_profile);
    saveBtn = findViewById(R.id.edit_profile_save_button);
    ageGroup = findViewById(R.id.radio_group_age);
    budgetGroup = findViewById(R.id.radio_group_budget);
    radiusGroup = findViewById(R.id.radio_group_radius);
    firstName = findViewById(R.id.edit_profile_firstname);
    lastName = findViewById(R.id.edit_profile_lastname);
    zipCode = findViewById(R.id.edit_profile_zip_code);
    mAuth = FirebaseAuth.getInstance();
    rootRef = FirebaseDatabase.getInstance().getReference();
    publicUserReference = rootRef.child(PUBLIC_USER);
    privateUserReference = rootRef.child(PRIVATE_USER);
    privateUserLocationReference = rootRef.child(PRIVATE_USER);
    userIconReference = rootRef.child(USER_ICON);
    currentUser = mAuth.getCurrentUser();
    currentUserID = currentUser.getUid();
    currentUserEmail = currentUser.getEmail();
    radioGroupSelection();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (currentUser != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + currentUser.getUid());
            // Toast.makeText(EditProfileActivity.this, "Successfully signed in with: " + currentUser.getEmail(), Toast.LENGTH_SHORT).show();
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            // Toast.makeText(EditProfileActivity.this, "Successfully signed out.", Toast.LENGTH_SHORT).show();
            }
        }
    };
    ValueEventListener valueEventListener = new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            privateUser = dataSnapshot.child(currentUserID).getValue(PrivateUser.class);
            privateUserLocation = dataSnapshot.child(currentUserID).getValue(PrivateUserLocation.class);
            publicUser = dataSnapshot.child(currentUserID).getValue(PublicUser.class);
            userIcon = dataSnapshot.child(currentUserID).getValue(UserIcon.class);
            iconUrl = userIcon.getIcon_url();
            Log.d(TAG, "onDataChange: Added information to database: \n" + dataSnapshot.getValue());
        }

        @Override
        public void onCancelled(DatabaseError error) {
            // Failed to read value
            Log.w(TAG, "Failed to read value.", error.toException());
        }
    };
    publicUserReference.addValueEventListener(valueEventListener);
    privateUserReference.addValueEventListener(valueEventListener);
    privateUserLocationReference.addValueEventListener(valueEventListener);
    userIconReference.addListenerForSingleValueEvent(valueEventListener);
    saveBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveToDatabase();
        }
    });
    // /////////////////////////////////////////
    /**
     * code below needs to be place in the launch of the app so the user can give location
     * permission beforehand.
     */
    LocationManager locationManager = (LocationManager) getSystemService(this.LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION, android.Manifest.permission.ACCESS_COARSE_LOCATION }, 1020);
        share_location = true;
        return;
    }
/* Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        lat = location.getLatitude();
        lng = location.getLongitude();*/
}
Also used : PrivateUser(com.example.c4q.capstone.database.privateuserdata.PrivateUser) LocationManager(android.location.LocationManager) PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) PrivateUserLocation(com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) ValueEventListener(com.google.firebase.database.ValueEventListener) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Aggregations

PublicUser (com.example.c4q.capstone.database.publicuserdata.PublicUser)17 DataSnapshot (com.google.firebase.database.DataSnapshot)8 DatabaseError (com.google.firebase.database.DatabaseError)8 ValueEventListener (com.google.firebase.database.ValueEventListener)8 UserIcon (com.example.c4q.capstone.database.publicuserdata.UserIcon)6 PrivateUser (com.example.c4q.capstone.database.privateuserdata.PrivateUser)4 PrivateUserLocation (com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation)4 View (android.view.View)3 FBUserDataListener (com.example.c4q.capstone.utils.FBUserDataListener)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2 HashMap (java.util.HashMap)2 Intent (android.content.Intent)1 LocationManager (android.location.LocationManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 EventGuest (com.example.c4q.capstone.database.events.EventGuest)1 Venue (com.example.c4q.capstone.database.events.Venue)1 PublicUserDetails (com.example.c4q.capstone.database.publicuserdata.PublicUserDetails)1 ContactListAdapter (com.example.c4q.capstone.userinterface.user.userprofilefragments.userprofilecontroller.ContactListAdapter)1 ContactListViewHolder (com.example.c4q.capstone.userinterface.user.userprofilefragments.userprofileviews.ContactListViewHolder)1