MobApp/app/src/main/java/com/example/monagendapartage/Fragments/CommonFragment/ProfilFragment.java
/** Fonction permettant d'uploader la nouvelle image de l'utilisateur sur Firebase Storage */
Fonction permettant d'uploader la nouvelle image de l'utilisateur sur Firebase Storage
Fonction permettant d ' uploader la nouvelle image de l ' utilisateur sur Firebase Storage
private void uploadImage() {
        final ProgressDialog pd = new ProgressDialog(getContext());
        pd.setMessage("Uploading");
        pd.show();
        if (imageUri != null) {
            final StorageReference fileReference = storageReference.child(System.currentTimeMillis()
                    +"."+getFileExtension(imageUri));
            uploadTask = fileReference.putFile(imageUri);
            uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
                @Override
                public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw  task.getException();
                    }
                    return fileReference.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                @Override
                public void onComplete(@NonNull Task<Uri> task) {
                    if (task.isSuccessful()) {
                        Uri downloadUri = task.getResult();
                        String mUri = downloadUri.toString();
                        reference = FirebaseDatabase.getInstance().getReference("Users").child(fuser.getUid());
                        HashMap<String, Object> map = new HashMap<>();
                        map.put("imageURL", mUri);
                        reference.updateChildren(map);
                        pd.dismiss();
                    } else {
                        Toast.makeText(getContext(), "Upload echoué !", Toast.LENGTH_SHORT).show();
                        pd.dismiss();
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                    pd.dismiss();
                }
            });
        } else {
            Toast.makeText(getContext(), "Aucune image n'a été séléctionné", Toast.LENGTH_SHORT).show();
        }
    }
private void uploadImage ( ) { final ProgressDialog pd = new ProgressDialog ( getContext ( ) ) ; pd . setMessage ( "Uploading" ) ; pd . show ( ) ; if ( imageUri != null ) { final StorageReference fileReference = storageReference . child ( System . currentTimeMillis ( ) + "." + getFileExtension ( imageUri ) ) ; uploadTask = fileReference . putFile ( imageUri ) ; uploadTask . continueWithTask ( new Continuation < UploadTask . TaskSnapshot , Task < Uri > > ( ) { @ Override public Task < Uri > then ( @ NonNull Task < UploadTask . TaskSnapshot > task ) throws Exception { if ( ! task . isSuccessful ( ) ) { throw task . getException ( ) ; } return fileReference . getDownloadUrl ( ) ; } } ) . addOnCompleteListener ( new OnCompleteListener < Uri > ( ) { @ Override public void onComplete ( @ NonNull Task < Uri > task ) { if ( task . isSuccessful ( ) ) { Uri downloadUri = task . getResult ( ) ; String mUri = downloadUri . toString ( ) ; reference = FirebaseDatabase . getInstance ( ) . getReference ( "Users" ) . child ( fuser . getUid ( ) ) ; HashMap < String , Object > map = new HashMap < > ( ) ; map . put ( "imageURL" , mUri ) ; reference . updateChildren ( map ) ; pd . dismiss ( ) ; } else { Toast . makeText ( getContext ( ) , "Upload echoué !", oast. L ENGTH_SHORT) . s how( ) ; pd . dismiss ( ) ; } } } ) . addOnFailureListener ( new OnFailureListener ( ) { @ Override public void onFailure ( @ NonNull Exception e ) { Toast . makeText ( getContext ( ) , e . getMessage ( ) , Toast . LENGTH_SHORT ) . show ( ) ; pd . dismiss ( ) ; } } ) ; } else { Toast . makeText ( getContext ( ) , "Aucune image n'a été séléctionné", Toa s .LENG T H_SHORT).sho w ( ); } }
Fonction permettant d'uploader la nouvelle image de l'utilisateur sur Firebase Storage
Fonction permettant d ' uploader la nouvelle image de l ' utilisateur sur Firebase Storage