use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class AppointmentsFragment method fetchData.
// Getting data from database
public void fetchData() {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
appointments.clear();
keys.clear();
for (DataSnapshot child : dataSnapshot.getChildren()) {
Appointment appointment = child.getValue(Appointment.class);
appointments.add(appointment);
keys.add(child.getKey());
}
numAppointments.setText("Appointments: " + appointments.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class AppointmentsOrgFragment method fetchData.
// Getting data from database
public void fetchData() {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("orgid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
appointments.clear();
keys.clear();
for (DataSnapshot child : dataSnapshot.getChildren()) {
Appointment appointment = child.getValue(Appointment.class);
appointments.add(appointment);
keys.add(child.getKey());
}
numAppointments.setText("Appointments: " + appointments.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class IndividualRegistrationActivity method registerNewUser.
private void registerNewUser() {
email = mEmailView.getText().toString().trim();
password = mPasswordView.getText().toString().trim();
uname = username.getText().toString();
bgroup = bloodGroup.getSelectedItem().toString();
if (uname.isEmpty()) {
Toast.makeText(this, "You forgot to enter your name.", Toast.LENGTH_SHORT).show();
} else {
if (!isEmailValid(email)) {
Toast.makeText(this, "Not a valid email address", Toast.LENGTH_SHORT).show();
} else {
if (!isPasswordValid(password)) {
Toast.makeText(this, "Password is too short, minimum length is 6.", Toast.LENGTH_SHORT).show();
} else {
if (bgroup.contentEquals("Blood Group")) {
Toast.makeText(this, "You forgot to choose your blood group.", Toast.LENGTH_SHORT).show();
} else {
// register user with firebase
// progressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Context context = getApplicationContext();
// progressBar.setVisibility(View.GONE);
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
Toast.makeText(context, "Registration Successful!", Toast.LENGTH_SHORT).show();
// set default subscriptions
int id = Arrays.asList(getResources().getStringArray(R.array.blood_groups)).indexOf(bgroup);
FirebaseMessaging.getInstance().subscribeToTopic("Request_" + id);
FirebaseMessaging.getInstance().subscribeToTopic("URGENT");
// take user to main screen
sendVerificationEmail();
writeNewUser(user.getUid(), user.getEmail());
Intent intent = new Intent(context, LoginActivity.class);
startActivity(intent);
} else {
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
Toast.makeText(context, "User with this email already exists.", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Error creating user", Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
}
}
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class LoginActivity method attemptLogin.
private void attemptLogin() {
// Reset errors.
mEmailView.setError(null);
mPasswordView.setError(null);
// Store values at the time of the login attempt.
String email = mEmailView.getText().toString();
String password = mPasswordView.getText().toString();
boolean cancel = false;
View focusView = null;
// Check for a valid password, if the user entered one.
if (TextUtils.isEmpty(password) && !isPasswordValid(password)) {
mPasswordView.setError(getString(R.string.error_invalid_password));
focusView = mPasswordView;
cancel = true;
}
// Check for a valid email address.
if (TextUtils.isEmpty(email)) {
mEmailView.setError(getString(R.string.error_field_required));
focusView = mEmailView;
cancel = true;
} else if (!isEmailValid(email)) {
mEmailView.setError(getString(R.string.error_invalid_email));
focusView = mEmailView;
cancel = true;
}
if (cancel) {
// There was an error; don't attempt login and focus the first
// form field with an error.
focusView.requestFocus();
} else {
// Show a progress spinner, and kick off a background task to
// perform the user login attempt.
showProgress(true);
final Context context = getApplicationContext();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
if (user.isEmailVerified()) {
setView(user.getUid(), user.getEmail());
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Please verify email address", Toast.LENGTH_SHORT);
toast.show();
showProgress(false);
FirebaseAuth.getInstance().signOut();
}
} else {
showProgress(false);
Toast.makeText(context, "Authentication failed.", Toast.LENGTH_SHORT).show();
}
}
});
}
}
use of com.google.firebase.auth.FirebaseUser in project BloodHub by kazijehangir.
the class MyRequestsFragment method fetchData.
// Getting data from database
public void fetchData() {
requests = new ArrayList<BloodRequest>();
keys = new ArrayList<String>();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
requests.clear();
keys.clear();
for (DataSnapshot child : dataSnapshot.getChildren()) {
BloodRequest request = child.getValue(BloodRequest.class);
requests.add(request);
keys.add(child.getKey());
}
numRequests.setText("Total Requests: " + requests.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return;
}
Aggregations