Search in sources :

Example 6 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata 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 7 with StorageMetadata

use of com.google.firebase.storage.StorageMetadata in project BORED by invent2017.

the class MultiSquawk method uploadImage.

private void uploadImage(Uri file) {
    // String fileUri = file.toString();
    // File imageFile = new File(fileUri);
    StorageMetadata metadata = new StorageMetadata.Builder().setContentType("image/jpg").build();
    String imageFileName = file.getLastPathSegment();
    // TODO: check if image with same name already exists
    UploadTask uploadTask = mStorageRef.child(imageFileName).putFile(file, metadata);
    uploadTask.addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
            builder.setMessage("Upload failed. Please try again later.").setPositiveButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent i = new Intent(MultiSquawk.this, MapsActivityCurrentPlace.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            });
            builder.create().show();
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            uploadImageData(taskSnapshot);
        }
    });
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UploadTask(com.google.firebase.storage.UploadTask) NonNull(android.support.annotation.NonNull) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

StorageMetadata (com.google.firebase.storage.StorageMetadata)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 NonNull (android.support.annotation.NonNull)3 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)3 UploadTask (com.google.firebase.storage.UploadTask)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 AlertDialog (android.support.v7.app.AlertDialog)2 StorageReference (com.google.firebase.storage.StorageReference)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)1