Search in sources :

Example 26 with OnSuccessListener

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);
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) IdpResponse(com.firebase.ui.auth.IdpResponse)

Example 27 with OnSuccessListener

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));
            }
        }
    });
}
Also used : FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException) TaskFailureLogger(com.firebase.ui.auth.ui.TaskFailureLogger) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FirebaseAuthInvalidUserException(com.google.firebase.auth.FirebaseAuthInvalidUserException)

Example 28 with OnSuccessListener

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();
        }
    });
}
Also used : UploadTask(com.google.firebase.storage.UploadTask) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 29 with OnSuccessListener

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);
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 30 with OnSuccessListener

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]
        }
    });
}
Also used : UploadTask(com.google.firebase.storage.UploadTask) StorageReference(com.google.firebase.storage.StorageReference) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) Uri(android.net.Uri) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)44 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)43 StorageReference (com.google.firebase.storage.StorageReference)13 UploadTask (com.google.firebase.storage.UploadTask)10 File (java.io.File)9 AuthResult (com.google.firebase.auth.AuthResult)8 Uri (android.net.Uri)7 ApiException (com.google.android.gms.common.api.ApiException)6 FileDownloadTask (com.google.firebase.storage.FileDownloadTask)6 IOException (java.io.IOException)6 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)5 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)4 InputImage (com.google.mlkit.vision.common.InputImage)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 WritableArray (com.facebook.react.bridge.WritableArray)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 OnProgressListener (com.google.firebase.storage.OnProgressListener)3 StorageMetadata (com.google.firebase.storage.StorageMetadata)3