Search in sources :

Example 6 with OnFailureListener

use of com.google.android.gms.tasks.OnFailureListener in project RSAndroidApp by RailwayStations.

the class AuthActivity method fetchConfig.

// Fetch the config to determine the allowed length of messages.
public void fetchConfig() {
    // 1 hour in seconds
    long cacheExpiration = 3600;
    // server. This should not be used in release builds.
    if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
        cacheExpiration = 0;
    }
    mFirebaseRemoteConfig.fetch(cacheExpiration).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            // Make the fetched config available via FirebaseRemoteConfig get<type> calls.
            mFirebaseRemoteConfig.activateFetched();
            applyRetrievedLengthLimit();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            // There has been an error fetching the config
            Log.w(TAG, "Error fetching config: " + e.getMessage());
            applyRetrievedLengthLimit();
        }
    });
}
Also used : OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 7 with OnFailureListener

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

the class PresetStoreAdapter method onFirebasePresetUpdated.

private void onFirebasePresetUpdated(final String presetName, final Runnable onUpdated) {
    StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets/" + presetName).child("preset.zip");
    metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            if (storageMetadata.getUpdatedTimeMillis() > new File(PROJECT_LOCATION_PRESETS + "/" + presetName + "/about/json.txt").lastModified()) {
                // firebase preset is updated since last download
                // get the new updated preset
                Log.d(TAG, "Preset updated");
                onUpdated.run();
            } else {
                Log.d(TAG, "Preset not updated");
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get preset metadata");
        }
    });
}
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 8 with OnFailureListener

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

the class FirebaseHelper method getStorageMetadata.

public StorageMetadata getStorageMetadata(StorageReference storageReference, Activity activity) {
    FirebaseApp.initializeApp(activity);
    final StorageMetadata[] mStorageMetadata = { null };
    storageReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            mStorageMetadata[0] = storageMetadata;
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get metadata");
        }
    });
    return mStorageMetadata[0];
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 9 with OnFailureListener

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

the class FirebaseHelper method saveFirebaseMetadata.

public FirebaseMetadata saveFirebaseMetadata(StorageReference storageReference, final String fileLocation, 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);
                }
            }).addOnFailureListener(new OnFailureListener() {

                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e(TAG, "Failed to download");
                }
            });
        } else {
            Log.e(TAG, "Not connected to the internet");
        }
    }
    return getFirebaseMetadata(activity);
}
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)

Example 10 with OnFailureListener

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

the class PresetStoreActivity method downloadMetadata.

private void downloadMetadata() {
    // loading start
    setLoadingFinished(false);
    Log.d(TAG, "downloadMetaData");
    boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    if (!hasPermission) {
        ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
    }
    // Make sdcard/Tapad folder
    File folder = new File(tapadFolderPath);
    if (folder.mkdirs()) {
        Log.i(TAG, "folder successfully created");
    } else {
        // folder exists
        Log.e(TAG, "folder already exists");
    }
    // Make sdcard/Tapad/presets folder
    File presets = new File(tapadFolderPath + "/presets");
    if (presets.mkdirs()) {
        Log.i(TAG, "folder successfully created");
    } else {
        // folder exists
        Log.e(TAG, "folder already exists");
    }
    final File metadata = new File(tapadFolderPath + "/presets/metadata.txt");
    StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
    metadataReference.getFile(metadata).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {

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

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.e(TAG, "Failed to download");
        }
    });
}
Also used : FileDownloadTask(com.google.firebase.storage.FileDownloadTask) StorageReference(com.google.firebase.storage.StorageReference) 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