Search in sources :

Example 16 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener 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 17 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener 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 18 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener 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 19 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.

the class PresetStoreActivity method isFirebaseMetadataUpdated.

private boolean isFirebaseMetadataUpdated(Context context) {
    isFMUpdated = false;
    if (isConnected(context)) {
        Log.d(TAG, "Connected to the internet");
        StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
        metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

            @Override
            public void onSuccess(StorageMetadata storageMetadata) {
                Log.d(TAG, "Successful getting metadata");
                if (storageMetadata.getUpdatedTimeMillis() > new File(metadataLocation).lastModified()) {
                    // firebase metadata is updated since last download
                    // get the new updated metadata
                    Log.d(TAG, "File updated");
                    isFMUpdated = true;
                } else {
                    Log.d(TAG, "File not updated");
                    isFMUpdated = false;
                }
            }
        }).addOnFailureListener(new OnFailureListener() {

            @Override
            public void onFailure(@NonNull Exception e) {
                Log.d(TAG, "Failed to get metadata");
                isFMUpdated = false;
            }
        });
        return isFMUpdated;
    } else {
        Log.d(TAG, "Disconnected from the internet");
        return isFMUpdated;
    }
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) StorageReference(com.google.firebase.storage.StorageReference) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) File(java.io.File) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 20 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener in project Tapad by berict.

the class FirebaseHelper method saveFromFirebase.

public void saveFromFirebase(StorageReference storageReference, final String fileLocation, final Runnable onSuccess, final Runnable onFailure, Activity activity) {
    // permission check
    boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    if (!hasPermission) {
        // no permission
        Log.e(TAG, "No permission acquired");
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
    } else {
        if (isConnected(activity)) {
            File file = new File(fileLocation);
            storageReference.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {

                @Override
                public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                    Log.d(TAG, "Successful download at " + fileLocation);
                    onSuccess.run();
                }
            }).addOnFailureListener(new OnFailureListener() {

                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e(TAG, "Failed to download");
                    onFailure.run();
                }
            });
        } else {
            Log.e(TAG, "Not connected to the internet");
        }
    }
}
Also used : FileDownloadTask(com.google.firebase.storage.FileDownloadTask) File(java.io.File) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

OnFailureListener (com.google.android.gms.tasks.OnFailureListener)23 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)14 StorageReference (com.google.firebase.storage.StorageReference)8 UploadTask (com.google.firebase.storage.UploadTask)6 NonNull (android.support.annotation.NonNull)5 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)5 FirebaseUser (com.google.firebase.auth.FirebaseUser)5 File (java.io.File)5 Bitmap (android.graphics.Bitmap)4 AuthResult (com.google.firebase.auth.AuthResult)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Uri (android.net.Uri)3 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)3 FileDownloadTask (com.google.firebase.storage.FileDownloadTask)3 StorageMetadata (com.google.firebase.storage.StorageMetadata)3 HashMap (java.util.HashMap)3 IdpResponse (com.firebase.ui.auth.IdpResponse)2 AuthCredential (com.google.firebase.auth.AuthCredential)2 FirebaseAuthWeakPasswordException (com.google.firebase.auth.FirebaseAuthWeakPasswordException)2 IOException (java.io.IOException)2