Search in sources :

Example 1 with UserIcon

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

the class CreateProfileFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(com.example.c4q.capstone.R.layout.fragment_create_profile, container, false);
    // saveBtn = rootView.findViewById(R.id.create_profile_save_button);
    ageGroup = rootView.findViewById(R.id.radio_group_age);
    budgetGroup = rootView.findViewById(R.id.radio_group_budget);
    radiusGroup = rootView.findViewById(R.id.radio_group_radius);
    firstName = rootView.findViewById(R.id.edit_profile_firstname);
    lastName = rootView.findViewById(R.id.edit_profile_lastname);
    zipCode = rootView.findViewById(R.id.edit_profile_zip_code);
    rootRef = FirebaseDatabase.getInstance().getReference();
    publicUserReference = rootRef.child(PUBLIC_USER);
    privateUserReference = rootRef.child(PRIVATE_USER);
    privateUserLocationReference = rootRef.child(PRIVATE_USER);
    userIconReference = rootRef.child(USER_ICON);
    mAuth = FirebaseAuth.getInstance();
    currentUser = mAuth.getCurrentUser();
    currentUserID = currentUser.getUid();
    currentUserEmail = currentUser.getEmail();
    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);
            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.addValueEventListener(valueEventListener);
    saveBtn = rootView.findViewById(R.id.create_profile_save_button);
    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();
            }
        }
    };
    saveBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveToDatabase();
        }
    });
    return rootView;
}
Also used : PrivateUser(com.example.c4q.capstone.database.privateuserdata.PrivateUser) PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) DatabaseError(com.google.firebase.database.DatabaseError) PrivateUserLocation(com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 2 with UserIcon

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

the class CreateProfileFragment 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);
        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(CreateProfileFragment.this.getActivity(), 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)

Example 3 with UserIcon

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

the class TempUserActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_PHOTO_PICKER) {
        try {
            final Uri uri = data.getData();
            UserIcon test = new UserIcon("hello");
            iconRef.setValue(test, new DatabaseReference.CompletionListener() {

                @Override
                public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
                    if (databaseError == null) {
                        StorageReference storage = FirebaseStorage.getInstance().getReference(USER_ICON).child(currentUserId).child(uri.getLastPathSegment());
                        storage.putFile(uri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
                                if (task.isSuccessful()) {
                                    UserIcon test = new UserIcon(task.getResult().getMetadata().getDownloadUrl().toString());
                                    iconRef.setValue(test);
                                    CurrentUserPost.getInstance().postProfilePictoPublicUser(test);
                                }
                            }
                        });
                    }
                }
            });
        } catch (NullPointerException e) {
            e.printStackTrace();
        }
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) UploadTask(com.google.firebase.storage.UploadTask) DatabaseError(com.google.firebase.database.DatabaseError) StorageReference(com.google.firebase.storage.StorageReference) DatabaseReference(com.google.firebase.database.DatabaseReference) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) NonNull(android.support.annotation.NonNull) Uri(android.net.Uri)

Example 4 with UserIcon

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

the class NewEventConverter method convertPubDetailsToPubUser.

public PublicUser convertPubDetailsToPubUser(PublicUserDetails publicUserDetails) {
    PublicUser user = new PublicUser();
    user.setRadius(Integer.parseInt(publicUserDetails.getRadius()));
    user.setZip_code(String.valueOf(publicUserDetails.getZip_code()));
    UserIcon userIcon = new UserIcon();
    userIcon.setIcon_url(publicUserDetails.getIcon_url());
    user.setUser_icon(userIcon);
    user.setFirst_name(publicUserDetails.getFirst_name());
    user.setLast_name(publicUserDetails.getLast_name());
    user.setUser_id(publicUserDetails.getUid());
    return user;
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon)

Example 5 with UserIcon

use of com.example.c4q.capstone.database.publicuserdata.UserIcon 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)

Aggregations

UserIcon (com.example.c4q.capstone.database.publicuserdata.UserIcon)8 PublicUser (com.example.c4q.capstone.database.publicuserdata.PublicUser)6 PrivateUser (com.example.c4q.capstone.database.privateuserdata.PrivateUser)4 PrivateUserLocation (com.example.c4q.capstone.database.privateuserdata.PrivateUserLocation)4 DatabaseError (com.google.firebase.database.DatabaseError)4 DataSnapshot (com.google.firebase.database.DataSnapshot)3 ValueEventListener (com.google.firebase.database.ValueEventListener)3 View (android.view.View)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2 Intent (android.content.Intent)1 LocationManager (android.location.LocationManager)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)1 Task (com.google.android.gms.tasks.Task)1 DatabaseReference (com.google.firebase.database.DatabaseReference)1 StorageReference (com.google.firebase.storage.StorageReference)1 UploadTask (com.google.firebase.storage.UploadTask)1