use of com.google.firebase.auth.FirebaseAuth 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.FirebaseAuth 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;
}
use of com.google.firebase.auth.FirebaseAuth in project FirebaseAuth-Android by jirawatee.
the class TwitterLoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Configure Twitter SDK
TwitterAuthConfig authConfig = new TwitterAuthConfig(getString(R.string.twitter_consumer_key), getString(R.string.twitter_consumer_secret));
Fabric.with(this, new Twitter(authConfig));
// Inflate layout (must be done after Twitter is configured)
setContentView(R.layout.activity_twitter);
mImageView = findViewById(R.id.logo);
mTextViewProfile = findViewById(R.id.profile);
findViewById(R.id.button_twitter_signout).setOnClickListener(this);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
}
updateUI(user);
}
};
// initialize_twitter_login
mLoginButton = findViewById(R.id.button_twitter_login);
mLoginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
Log.d(TAG, "twitterLogin:success" + result);
handleTwitterSession(result.data);
}
@Override
public void failure(TwitterException exception) {
Log.w(TAG, "twitterLogin:failure", exception);
updateUI(null);
}
});
}
use of com.google.firebase.auth.FirebaseAuth in project FirebaseAuth-Android by jirawatee.
the class FacebookLoginActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook);
mImageView = findViewById(R.id.logo);
mTextViewProfile = findViewById(R.id.profile);
findViewById(R.id.button_facebook_signout).setOnClickListener(this);
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
}
updateUI(user);
}
};
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = findViewById(R.id.button_facebook_login);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
updateUI(null);
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
updateUI(null);
}
});
}
use of com.google.firebase.auth.FirebaseAuth in project FirebaseUI-Android by firebase.
the class AuthUI method delete.
/**
* Delete the use from FirebaseAuth and delete any associated credentials from the Credentials
* API. Returns a {@link Task} that succeeds if the Firebase Auth user deletion succeeds and
* fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
* silently.
*
* @param context the calling {@link Context}.
*/
@NonNull
public Task<Void> delete(@NonNull final Context context) {
final FirebaseUser currentUser = mAuth.getCurrentUser();
if (currentUser == null) {
return Tasks.forException(new FirebaseAuthInvalidUserException(String.valueOf(CommonStatusCodes.SIGN_IN_REQUIRED), "No currently signed in user."));
}
final List<Credential> credentials = getCredentialsFromFirebaseUser(currentUser);
// Ensure the order in which tasks are executed properly destructures the user.
return signOutIdps(context).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
Log.w(TAG, "Google Play services not available during delete");
return Tasks.forResult((Void) null);
}
final CredentialsClient client = GoogleApiUtils.getCredentialsClient(context);
List<Task<?>> credentialTasks = new ArrayList<>();
for (Credential credential : credentials) {
credentialTasks.add(client.delete(credential));
}
return Tasks.whenAll(credentialTasks).continueWith(task1 -> {
Exception e = task1.getException();
Throwable t = e == null ? null : e.getCause();
if (!(t instanceof ApiException) || ((ApiException) t).getStatusCode() != CommonStatusCodes.CANCELED) {
// doesn't mean fully deleting the user failed.
return task1.getResult();
}
return null;
});
}).continueWithTask(task -> {
// Propagate exception if there was one
task.getResult();
return currentUser.delete();
});
}
Aggregations