use of com.google.android.gms.tasks.OnSuccessListener in project FirebaseUI-Android by firebase.
the class WelcomeBackPasswordPrompt method next.
private void next(final String email, final String password) {
// Check for null or empty password
if (TextUtils.isEmpty(password)) {
mPasswordLayout.setError(getString(R.string.required_field));
return;
} else {
mPasswordLayout.setError(null);
}
mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
final FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();
// Sign in with known email and the password provided
firebaseAuth.signInWithEmailAndPassword(email, password).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with email and password")).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
AuthCredential authCredential = AuthCredentialHelper.getAuthCredential(mIdpResponse);
// Otherwise, the user has an email account that we need to link to an idp.
if (authCredential == null) {
mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), password, new IdpResponse(EmailAuthProvider.PROVIDER_ID, email));
} else {
authResult.getUser().linkWithCredential(authCredential).addOnFailureListener(new TaskFailureLogger(TAG, "Error signing in with credential " + authCredential.getProvider())).addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
mActivityHelper.saveCredentialsOrFinish(mSaveSmartLock, authResult.getUser(), mIdpResponse);
}
});
}
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mActivityHelper.dismissDialog();
String error = e.getLocalizedMessage();
mPasswordLayout.setError(error);
}
});
}
use of com.google.android.gms.tasks.OnSuccessListener in project FirebaseUI-Android by firebase.
the class RecoverPasswordActivity method next.
private void next(final String email) {
mActivityHelper.getFirebaseAuth().sendPasswordResetEmail(email).addOnFailureListener(new TaskFailureLogger(TAG, "Error sending password reset email")).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
mActivityHelper.dismissDialog();
RecoveryEmailSentDialog.show(email, getSupportFragmentManager());
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
mActivityHelper.dismissDialog();
if (e instanceof FirebaseAuthInvalidUserException) {
// No FirebaseUser exists with this email address, show error.
mEmailEditText.setError(getString(R.string.error_email_does_not_exist));
}
}
});
}
use of com.google.android.gms.tasks.OnSuccessListener in project FirebaseUI-Android by firebase.
the class ImageActivity method uploadPhoto.
private void uploadPhoto(Uri uri) {
// Reset UI
hideDownloadUI();
Toast.makeText(this, "Uploading...", Toast.LENGTH_SHORT).show();
// Upload to Cloud Storage
String uuid = UUID.randomUUID().toString();
mImageRef = FirebaseStorage.getInstance().getReference(uuid);
mImageRef.putFile(uri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//noinspection LogConditional
Log.d(TAG, "uploadPhoto:onSuccess:" + taskSnapshot.getMetadata().getReference().getPath());
Toast.makeText(ImageActivity.this, "Image uploaded", Toast.LENGTH_SHORT).show();
showDownloadUI();
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "uploadPhoto:onError", e);
Toast.makeText(ImageActivity.this, "Upload failed", Toast.LENGTH_SHORT).show();
}
});
}
use of com.google.android.gms.tasks.OnSuccessListener in project quickstart-android by firebase.
the class MainActivity method signInAnonymously.
private void signInAnonymously() {
// Sign in anonymously. Authentication is required to read or write from Firebase Storage.
showProgressDialog(getString(R.string.progress_auth));
mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
Log.d(TAG, "signInAnonymously:SUCCESS");
hideProgressDialog();
updateUI(authResult.getUser());
}
}).addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e(TAG, "signInAnonymously:FAILURE", exception);
hideProgressDialog();
updateUI(null);
}
});
}
use of com.google.android.gms.tasks.OnSuccessListener in project quickstart-android by firebase.
the class MyUploadService method uploadFromUri.
// [START upload_from_uri]
private void uploadFromUri(final Uri fileUri) {
Log.d(TAG, "uploadFromUri:src:" + fileUri.toString());
// [START_EXCLUDE]
taskStarted();
showProgressNotification(getString(R.string.progress_uploading), 0, 0);
// [END_EXCLUDE]
// [START get_child_ref]
// Get a reference to store file at photos/<FILENAME>.jpg
final StorageReference photoRef = mStorageRef.child("photos").child(fileUri.getLastPathSegment());
// [END get_child_ref]
// Upload file to Firebase Storage
Log.d(TAG, "uploadFromUri:dst:" + photoRef.getPath());
photoRef.putFile(fileUri).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
showProgressNotification(getString(R.string.progress_uploading), taskSnapshot.getBytesTransferred(), taskSnapshot.getTotalByteCount());
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Upload succeeded
Log.d(TAG, "uploadFromUri:onSuccess");
// Get the public download URL
Uri downloadUri = taskSnapshot.getMetadata().getDownloadUrl();
// [START_EXCLUDE]
broadcastUploadFinished(downloadUri, fileUri);
showUploadFinishedNotification(downloadUri, fileUri);
taskCompleted();
// [END_EXCLUDE]
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Upload failed
Log.w(TAG, "uploadFromUri:onFailure", exception);
// [START_EXCLUDE]
broadcastUploadFinished(null, fileUri);
showUploadFinishedNotification(null, fileUri);
taskCompleted();
// [END_EXCLUDE]
}
});
}
Aggregations