Search in sources :

Example 1 with User

use of com.example.flashgig.models.User in project FIREBASE_TEST_JAVA by essantos8.

the class LoginActivity method firebaseAuthWithGoogle.

private void firebaseAuthWithGoogle(String idToken, GoogleSignInAccount account) {
    AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
    mAuth.signInWithCredential(credential).addOnCompleteListener(this, task -> {
        if (task.isSuccessful()) {
            // Sign in success, update UI with the signed-in user's information
            Log.d("Google Sign In", "signInWithCredential:success");
            FirebaseFirestore db = FirebaseFirestore.getInstance();
            // Check if account is in database
            db.collection("users").whereEqualTo("email", account.getEmail()).get().addOnCompleteListener(task1 -> {
                if (task1.isSuccessful()) {
                    if (task1.getResult().size() > 0) {
                        Log.d("Google Sign In", "Existing account");
                    } else {
                        Log.d("Google Sign In", "New account, adding to Database");
                        User userData = new User(account.getDisplayName(), account.getEmail(), "", mAuth.getCurrentUser().getUid());
                        db.collection("users").document(mAuth.getCurrentUser().getUid()).set(userData);
                    }
                } else {
                    Toast.makeText(this, "Error accessing database!", Toast.LENGTH_SHORT).show();
                }
            });
            startActivity(new Intent(this, MainActivity.class));
        } else {
            // If sign in fails, display a message to the user.
            Log.w("Google Sign In", "signInWithCredential:failure", task.getException());
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.flashgig.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) Intent(android.content.Intent)

Example 2 with User

use of com.example.flashgig.models.User in project FIREBASE_TEST_JAVA by essantos8.

the class SignUpActivity method registerUser.

private void registerUser() {
    String fullName = tietnamesignup.getText().toString(), email = tietemailsignup.getText().toString(), password = tietpasswordsignup.getText().toString(), phone = tietnumbersignup.getText().toString();
    if (fullName.isEmpty()) {
        tilnamesignup.setError("Name is required!");
        return;
    }
    if (email.isEmpty()) {
        tilemailsignup.setError("Email is required!");
        return;
    }
    if (password.isEmpty()) {
        tilpasswordsignup.setError("Password is required!");
        return;
    }
    if (phone.isEmpty()) {
        tilnumbersignup.setError("Phone number is required!");
        return;
    }
    mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(SignUpActivity.this, task -> {
        if (task.isSuccessful()) {
            Toast.makeText(SignUpActivity.this, "User registered successfully!", Toast.LENGTH_LONG).show();
            FirebaseUser user = mAuth.getCurrentUser();
            // Update Database with new user info
            User data = new User(fullName, email, phone, user.getUid());
            db.collection("users").document(user.getUid()).set(data);
            FirebaseAuth.getInstance().signOut();
            finish();
            startActivity(new Intent(this, LoginActivity.class));
        } else {
            Toast.makeText(SignUpActivity.this, "Registration Failed!", Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : User(com.example.flashgig.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 3 with User

use of com.example.flashgig.models.User in project FIREBASE_TEST_JAVA by essantos8.

the class ProfileEditFragment method fetchUserInfo.

private void fetchUserInfo() {
    StorageReference userRef = storageRef.child("media/images/profile_pictures/" + currentUser.getUid());
    userRef.getMetadata().addOnSuccessListener(storageMetadata -> {
        GlideApp.with(this).load(userRef).signature(new ObjectKey(String.valueOf(storageMetadata.getCreationTimeMillis()))).fitCenter().into(profilePicture);
    }).addOnFailureListener(e -> {
        Log.d("Cloud Storage Access", "File not found!");
    });
    db.collection("users").document(currentUser.getUid()).get().addOnCompleteListener(task -> {
        user = task.getResult().toObject(User.class);
        binding.etName.setHint(user.getFullName());
        if (user.getAbout() != "") {
            binding.etAboutMe.setHint(user.getAbout());
        }
        if (user.getSkills().size() > 0) {
        // binding.
        }
    });
}
Also used : Bundle(android.os.Bundle) User(com.example.flashgig.models.User) RESULT_OK(android.app.Activity.RESULT_OK) Uri(android.net.Uri) ImageView(android.widget.ImageView) Intent(android.content.Intent) HashMap(java.util.HashMap) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Log(android.util.Log) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) FragmentManager(androidx.fragment.app.FragmentManager) GlideApp(com.example.flashgig.GlideApp) LayoutInflater(android.view.LayoutInflater) FirebaseUser(com.google.firebase.auth.FirebaseUser) ProgressDialog(android.app.ProgressDialog) R(com.example.flashgig.R) ViewGroup(android.view.ViewGroup) ObjectKey(com.bumptech.glide.signature.ObjectKey) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Nullable(androidx.annotation.Nullable) FragmentProfileEditBinding(com.example.flashgig.databinding.FragmentProfileEditBinding) StorageReference(com.google.firebase.storage.StorageReference) Snackbar(com.google.android.material.snackbar.Snackbar) User(com.example.flashgig.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) StorageReference(com.google.firebase.storage.StorageReference) ObjectKey(com.bumptech.glide.signature.ObjectKey)

Example 4 with User

use of com.example.flashgig.models.User in project FIREBASE_TEST_JAVA by essantos8.

the class ProfileFragment method retrieveInfo.

private void retrieveInfo(Boolean refresh) {
    StorageReference userRef = storageRef.child("media/images/profile_pictures/" + currentUser.getUid());
    userRef.getMetadata().addOnSuccessListener(storageMetadata -> {
        // Snackbar.make(binding.getRoot(), "File exists!", Snackbar.LENGTH_SHORT).show();
        if (refresh) {
        // 
        } else {
            GlideApp.with(this).load(userRef).signature(new ObjectKey(String.valueOf(storageMetadata.getCreationTimeMillis()))).fitCenter().into(profilePicture);
        }
        progressBar.setVisibility(View.GONE);
    }).addOnFailureListener(e -> {
        Log.d("Profile", "retrieveInfo: " + e.toString());
    // Snackbar.make(binding.getRoot(), "File does not exist!", Snackbar.LENGTH_SHORT).show();
    });
    db.collection("users").document(currentUser.getUid()).get().addOnCompleteListener(task -> {
        user = task.getResult().toObject(User.class);
        binding.textName.setText(user.getFullName());
        if (user.getAbout() != "") {
            binding.tvdesc.setText(user.getAbout());
        }
        if (user.getSkills().size() > 0) {
        // binding.
        }
    });
    db.collection("users").whereEqualTo("email", mAuth.getCurrentUser().getEmail()).get().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            QueryDocumentSnapshot user;
            if (!task.getResult().iterator().hasNext()) {
                Toast.makeText(getContext(), "User not found in database!", Toast.LENGTH_SHORT).show();
                Log.d("Profile", "user not in database");
                return;
            }
            user = task.getResult().iterator().next();
            textName.setText(user.getString("fullName"));
            textEmail.setText(user.getString("email"));
            textPhone.setText(user.getString("phone"));
        } else {
            Log.d("Profile", "Database error");
        }
    });
}
Also used : SplashActivity(com.example.flashgig.activities.SplashActivity) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) User(com.example.flashgig.models.User) ImageView(android.widget.ImageView) Intent(android.content.Intent) RequestListener(com.bumptech.glide.request.RequestListener) ReviewsActivity(com.example.flashgig.activities.ReviewsActivity) Drawable(android.graphics.drawable.Drawable) GlideException(com.bumptech.glide.load.engine.GlideException) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Fragment(androidx.fragment.app.Fragment) FragmentProfileBinding(com.example.flashgig.databinding.FragmentProfileBinding) View(android.view.View) JobAdderFragment(com.example.flashgig.JobAdderFragment) Log(android.util.Log) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) FirebaseStorage(com.google.firebase.storage.FirebaseStorage) GlideApp(com.example.flashgig.GlideApp) LayoutInflater(android.view.LayoutInflater) DataSource(com.bumptech.glide.load.DataSource) Target(com.bumptech.glide.request.target.Target) FirebaseUser(com.google.firebase.auth.FirebaseUser) R(com.example.flashgig.R) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) ObjectKey(com.bumptech.glide.signature.ObjectKey) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) StorageReference(com.google.firebase.storage.StorageReference) User(com.example.flashgig.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) StorageReference(com.google.firebase.storage.StorageReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ObjectKey(com.bumptech.glide.signature.ObjectKey)

Aggregations

Intent (android.content.Intent)4 User (com.example.flashgig.models.User)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)3 Bundle (android.os.Bundle)2 Log (android.util.Log)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 Toast (android.widget.Toast)2 Nullable (androidx.annotation.Nullable)2 Fragment (androidx.fragment.app.Fragment)2 ObjectKey (com.bumptech.glide.signature.ObjectKey)2 GlideApp (com.example.flashgig.GlideApp)2 R (com.example.flashgig.R)2 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)2 FirebaseStorage (com.google.firebase.storage.FirebaseStorage)2 StorageReference (com.google.firebase.storage.StorageReference)2 RESULT_OK (android.app.Activity.RESULT_OK)1