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());
}
});
}
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();
}
});
}
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.
}
});
}
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");
}
});
}
Aggregations