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);
}
});
}
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));
}
}
});
}
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();
}
});
}
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;
}
}
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");
}
}
}
Aggregations