Search in sources :

Example 6 with ElementString

use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.

the class CreateConstraintsWizard method savePhoto.

private void savePhoto(Uri photo, Element element, int i, long id) {
    final StorageReference fileRef = storegeProfilePick.child("PhotoObjects").child("Photo_Objects" + "_" + id);
    uploadTask = fileRef.putFile(photo);
    Task<Uri> urlTask = 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();
            }
            // Continue with the task to get the download URL
            return fileRef.getDownloadUrl();
        }
    }).addOnCompleteListener(new OnCompleteListener<Uri>() {

        @Override
        public void onComplete(@NonNull Task<Uri> task) {
            if (task.isSuccessful()) {
                Uri downloadUrl = task.getResult();
                uriUploadPhoto.add(downloadUrl.toString());
                // elm.put("Photo", uriUploadPhoto);
                db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (!queryDocumentSnapshots.isEmpty()) {
                            // lista zone
                            List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                            for (DocumentSnapshot d : listDocument) {
                                ElementString elme = d.toObject(ElementString.class);
                                if (elme.getTitle().matches(element.getTitle())) {
                                    HashMap<String, Object> userMap = new HashMap<>();
                                    userMap.put("photo", uriUploadPhoto.get(i));
                                    db.collection("Elements").document(d.getId()).update("photo", uriUploadPhoto.get(i)).addOnSuccessListener(new OnSuccessListener<Void>() {

                                        @Override
                                        public void onSuccess(Void unused) {
                                            success = true;
                                        }
                                    }).addOnFailureListener(new OnFailureListener() {

                                        @Override
                                        public void onFailure(@NonNull Exception e) {
                                            success = false;
                                            Toast.makeText(getContext(), "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
                                            loadingBar.setVisibility(View.GONE);
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
            } else {
            // Handle failures
            // ...
            }
        }
    });
}
Also used : Continuation(com.google.android.gms.tasks.Continuation) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) StorageReference(com.google.firebase.storage.StorageReference) HashMap(java.util.HashMap) ElementString(com.example.alphatour.oggetti.ElementString) Uri(android.net.Uri) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) UploadTask(com.google.firebase.storage.UploadTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) ElementString(com.example.alphatour.oggetti.ElementString) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 7 with ElementString

use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.

the class Step3 method setUserVisibleHint.

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        zone_selected.setText(DashboardActivity.getZona_scelta());
        String scelta = DashboardActivity.getZona_scelta();
        db.collection("Zones").whereEqualTo("name", scelta).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        String idZone = document.getId();
                        db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if (task.isSuccessful()) {
                                    for (QueryDocumentSnapshot document : task.getResult()) {
                                        ElementString element = document.toObject(ElementString.class);
                                        View object = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
                                        CheckableTextView textZone1 = (CheckableTextView) object.findViewById(R.id.textObjectss);
                                        textZone1.setText(element.getTitle());
                                        arrayStringElement.add(element.getTitle());
                                        // arrayObjectElement.add(element);
                                        arrayMonumenti.add(textZone1);
                                        delete_view.add(object);
                                        list_object.addView(object);
                                    }
                                } else {
                                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                    }
                } else {
                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                }
            }
        });
    } else {
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) CheckableTextView(com.devzone.checkabletextview.CheckableTextView) NonNull(androidx.annotation.NonNull) ElementString(com.example.alphatour.oggetti.ElementString) ElementString(com.example.alphatour.oggetti.ElementString) View(android.view.View) CheckableTextView(com.devzone.checkabletextview.CheckableTextView) TextView(android.widget.TextView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 8 with ElementString

use of com.example.alphatour.oggetti.ElementString in project AlphaTour by Frank99DG.

the class FileReceiverActivity method saveQrCode.

private void saveQrCode(String dataQr, Element element, int i, long id) {
    GenerateQrCodeClass generateQrCodeClass = new GenerateQrCodeClass(FileReceiverActivity.this);
    Bitmap qrCode = generateQrCodeClass.generateQrCode(dataQr);
    final StorageReference fileRef = storegeProfilePick.child("QrCodeObjects").child("QrCode_Objects" + "_" + id);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    qrCode.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    byte[] data = baos.toByteArray();
    UploadTask uploadTask = fileRef.putBytes(data);
    uploadTask.addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            uploadTask.continueWithTask(new Continuation() {

                @Override
                public Object then(@NonNull Task task) throws Exception {
                    if (!task.isSuccessful()) {
                        throw task.getException();
                    }
                    return fileRef.getDownloadUrl();
                }
            }).addOnCompleteListener(new OnCompleteListener() {

                @Override
                public void onComplete(@NonNull Task task) {
                    if (task.isSuccessful()) {
                        // scarico il link di Storage dell'immagine
                        Uri downloadUrl = (Uri) task.getResult();
                        uriUploadQrCode.add(downloadUrl.toString());
                        db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                            @Override
                            public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                if (!queryDocumentSnapshots.isEmpty()) {
                                    // lista zone
                                    List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                                    for (DocumentSnapshot d : listDocument) {
                                        ElementString elme = d.toObject(ElementString.class);
                                        if (elme.getTitle().matches(element.getTitle())) {
                                            HashMap<String, Object> userMap = new HashMap<>();
                                            userMap.put("qrCode", uriUploadQrCode.get(i));
                                            db.collection("Elements").document(d.getId()).update("qrCode", uriUploadQrCode.get(i)).addOnSuccessListener(new OnSuccessListener<Void>() {

                                                @Override
                                                public void onSuccess(Void unused) {
                                                    success = true;
                                                    Toast.makeText(FileReceiverActivity.this, "Zone e Oggetti creati con successo", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            }).addOnFailureListener(new OnFailureListener() {

                                                @Override
                                                public void onFailure(@NonNull Exception e) {
                                                    success = false;
                                                    Toast.makeText(FileReceiverActivity.this, "Non è stato possibile salvare le zone e gli oggetti creati!!!", Toast.LENGTH_LONG).show();
                                                    progressBar.setVisibility(View.GONE);
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }
    });
}
Also used : GenerateQrCodeClass(com.example.alphatour.qrcode.GenerateQrCodeClass) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) HashMap(java.util.HashMap) Uri(android.net.Uri) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) Bitmap(android.graphics.Bitmap) UploadTask(com.google.firebase.storage.UploadTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) List(java.util.List) ArrayList(java.util.ArrayList) ElementString(com.example.alphatour.oggetti.ElementString) Continuation(com.google.android.gms.tasks.Continuation) StorageReference(com.google.firebase.storage.StorageReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

ElementString (com.example.alphatour.oggetti.ElementString)8 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)8 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)7 NonNull (androidx.annotation.NonNull)6 Task (com.google.android.gms.tasks.Task)6 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)6 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)5 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)5 StorageTask (com.google.firebase.storage.StorageTask)5 UploadTask (com.google.firebase.storage.UploadTask)5 Uri (android.net.Uri)4 View (android.view.View)4 Continuation (com.google.android.gms.tasks.Continuation)4 StorageReference (com.google.firebase.storage.StorageReference)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3