Search in sources :

Example 6 with UserIcon

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

Example 7 with UserIcon

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

the class TempUserActivity method currentUserProfileData.

public void currentUserProfileData() {
    iconRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            UserIcon userIcon = dataSnapshot.getValue(UserIcon.class);
            try {
                String userIconUrl = userIcon.getIcon_url();
                Glide.with(TempUserActivity.this).load(userIconUrl).into(profilePic);
            } catch (NullPointerException e) {
                e.printStackTrace();
                profilePic.setImageResource(R.drawable.default_avatar);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    userRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            PublicUser publicUser = dataSnapshot.getValue(PublicUser.class);
            StringBuilder sb = new StringBuilder();
            sb.append(publicUser.getFirst_name());
            sb.append(" ");
            sb.append(publicUser.getLast_name());
            personName.setText(sb.toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
Also used : PublicUser(com.example.c4q.capstone.database.publicuserdata.PublicUser) DatabaseError(com.google.firebase.database.DatabaseError) UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 8 with UserIcon

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

the class EventInviteViewHolder method onBind.

public void onBind(UserEvent event, Context context) {
    eventOrganizer.setText(event.getEvent_organizer_full_name());
    eventName.setText(event.getEvent_name());
    eventDate.setText(event.getEvent_date());
    acceptButton.setTag(event.getEvent_id());
    UserIcon userIcon = event.getEvent_organizer_icon();
    if (userIcon != null) {
        String userIconUrl = userIcon.getIcon_url();
        Log.d(TAG, "user url " + userIconUrl);
        Glide.with(context).load(userIconUrl).into(organizerPhoto);
    }
}
Also used : UserIcon(com.example.c4q.capstone.database.publicuserdata.UserIcon)

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