use of com.google.firebase.auth.FirebaseAuth in project Grupp by tmoronta1208.
the class LoginActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// button views
signInButton = findViewById(R.id.google_button);
emailLogInButton = findViewById(R.id.btn_login);
// publicUserDatabaseReference = firebaseDatabase.getReference().child(Constants.PUBLIC_USER);
// getUserData();
emailLogInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
mAuthListner = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() != null) {
CurrentUserUtility currentUserUtility = new CurrentUserUtility();
currentUserUtility.getCurrentPublicUser(new PublicUserListener() {
@Override
public void publicUserExists(Boolean userExists) {
Log.w("TAG", "login user exist" + userExists);
if (userExists) {
Log.w("TAG", "login user has profile" + userExists);
startActivity(new Intent(LoginActivity.this, UserProfileActivity.class));
} else {
Log.w("TAG", "login user does not have profile " + userExists);
startActivity(new Intent(LoginActivity.this, OnBoardActivity.class));
}
}
});
startActivity(new Intent(LoginActivity.this, OnBoardActivity.class));
}
}
};
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.
the class DonationsFragment method fetchData.
// Getting data from database
public ArrayList<BloodRequest> fetchData() {
donations = new ArrayList<BloodRequest>();
FirebaseAuth mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Donation donation = child.getValue(Donation.class);
if (donation != null) {
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
if (request != null) {
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
donations.add(request);
numDonations.setText("LIVES SAVED: " + donations.size());
mAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return donations;
}
use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.
the class IndividualRegistrationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_individual_registration);
setTitle("Individual Registration");
// make the actionbar show arrow to go back to login
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Toast toast = Toast.makeText(getApplicationContext(), "Sending email", Toast.LENGTH_SHORT);
toast.show();
sendVerificationEmail();
} else {
Toast toast = Toast.makeText(getApplicationContext(), "Not sending email", Toast.LENGTH_SHORT);
toast.show();
}
}
};
username = (AutoCompleteTextView) findViewById(R.id.name);
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
mPasswordView = (EditText) findViewById(R.id.password);
// progressBar = (ProgressBar) findViewById(R.id.progressBar);
bloodGroup = (Spinner) findViewById(R.id.spin);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(bloodGroup);
popupWindow.setHeight(500);
} catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
}
List<String> bgroups = Arrays.asList(getResources().getStringArray(R.array.blood_groups));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_text_view, bgroups) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
v.setPadding(8, 8, 8, 15);
if (position == getCount()) {
((TextView) v.findViewById(R.id.text1)).setText("");
((TextView) v.findViewById(R.id.text1)).setHint(getItem(getCount()));
}
return v;
}
@Override
public int getCount() {
return super.getCount() - 1;
}
};
adapter.setDropDownViewResource(R.layout.spinner_text_view);
bloodGroup.setAdapter(adapter);
bloodGroup.setSelection(adapter.getCount());
// Set OnClick Listeners for buttons
photo_btn = (ImageButton) findViewById(R.id.profile_photo);
photo_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_INTENT);
}
});
Button mRegisterButton = (Button) findViewById(R.id.register_individual_button);
mRegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
registerNewUser();
}
});
}
use of com.google.firebase.auth.FirebaseAuth in project Firebase-Helper by AtifAbbAsi19.
the class FireBaseHelper method userLogin.
// method for user login
private void userLogin(String email, String password, Context context) {
// if the email and password are not empty
// displaying a progress dialog
progressDialog.setMessage("Logging in Please Wait...");
progressDialog.show();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
// logging in the user
firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// if the task is successfull
if (task.isSuccessful()) {
// start the profile activity
// Check in user Node that whether data exists or not
// if exists then login else show Snakbar data does not exist
// mAuthUserStr = mAuth.getCurrentUser().getUid();
// mEmail = mAuth.getCurrentUser().getEmail();
// AddEventFireBaseListner(mAuthUserStr, TypeSpinnerStr);
// startActivity(new Intent(getApplicationContext(), MainHomeDashBoard.class));
} else {
// Snackbar snackbar = Snackbar
// .make(coordinatorLayout, "Invalid user", Snackbar.LENGTH_LONG)
// .setAction("HIDE", new View.OnClickListener() {
// @Override
// public void onClick(View view) {
//
//
// }
// });
// snackbar.show();
progressDialog.dismiss();
}
}
});
}
use of com.google.firebase.auth.FirebaseAuth in project Firebase-Helper by AtifAbbAsi19.
the class FireBaseHelper method registerUser.
private void registerUser(final String email, String password, Context context) {
// if (TextUtils.isEmpty(phone_number)) {
// Toast.makeText(this, "Please enter Number", Toast.LENGTH_LONG).show();
// return;
// }
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
// if the email and password are not empty
// displaying a progress dialog
// progressDialog.setMessage("Registering Please Wait...");
// progressDialog.show();
// /http://stackoverflow.com/questions/40404567/how-to-send-verification-email-with-firebase
// .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
// .addOnCompleteListener((Executor) this, new OnCompleteListener<AuthResult>() {
// creating a new user
firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
// checking if success
if (task.isSuccessful()) {
// display some message here
String userId = task.getResult().getUser().getUid();
// Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
// startActivity(intent);
// https://firebase.googleblog.com/2017/02/email-verification-in-firebase-auth.html
// startActivity(new Intent(Signup_Activity.this, MainHomeDashBoard.class));
// Toast.makeText(getApplicationContext(), "Successfully registered", Toast.LENGTH_LONG).show();
} else {
if (task.getException() instanceof FirebaseAuthUserCollisionException) {
// Toast.makeText(Signup.this, "User with this email already exist.", Toast.LENGTH_SHORT).show();
}
//
// //display some message here
// Toast.makeText(getApplicationContext(), "Registration Error", Toast.LENGTH_LONG).show();
}
// progressDialog.dismiss();
}
});
}
Aggregations