Search in sources :

Example 1 with ElementString

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

the class ImportPhotoObjectActivity method saveQrCode.

private void saveQrCode(String dataQr, Element element, int i, long id) {
    GenerateQrCodeClass generateQrCodeClass = new GenerateQrCodeClass(ImportPhotoObjectActivity.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(ImportPhotoObjectActivity.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(ImportPhotoObjectActivity.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)

Example 2 with ElementString

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

the class ListElementsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_elements);
    // istanza oggetti firebase
    db = FirebaseFirestore.getInstance();
    auth = FirebaseAuth.getInstance();
    user = auth.getCurrentUser();
    idUser = user.getUid();
    Intent intent = getIntent();
    Place = intent.getStringExtra("Place");
    idPlace = intent.getStringExtra("idPlace");
    Zone = intent.getStringExtra("Zone");
    idZone = intent.getStringExtra("idZone");
    dashboardFlag = intent.getStringExtra("dashboardFlag");
    zoneText = findViewById(R.id.specificZoneText);
    zoneText.setText(Zone);
    layout_list = findViewById(R.id.listElementsLayout);
    db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
            if (!queryDocumentSnapshots.isEmpty()) {
                List<DocumentSnapshot> listDocuments = queryDocumentSnapshots.getDocuments();
                for (DocumentSnapshot d : listDocuments) {
                    ElementString element = d.toObject(ElementString.class);
                    final View elementView = getLayoutInflater().inflate(R.layout.row_update, null, false);
                    TextView editableElement = (TextView) elementView.findViewById(R.id.itemUpdateText);
                    editableElement.setText(element.getTitle());
                    layout_list.addView(elementView);
                    editableElement.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View elementView) {
                            db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                                @Override
                                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                                    if (!queryDocumentSnapshots.isEmpty()) {
                                        // lista elementi
                                        List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                                        for (DocumentSnapshot d : listDocument) {
                                            ElementString element = d.toObject(ElementString.class);
                                            if (editableElement.getText().toString().equals(element.getTitle())) {
                                                Intent intent = new Intent(ListElementsActivity.this, ModifyObjectActivity.class);
                                                myQrData = element.getQrData();
                                                intent.putExtra("data", myQrData);
                                                intent.putExtra("Place", Place);
                                                intent.putExtra("idPlace", idPlace);
                                                intent.putExtra("Zone", Zone);
                                                intent.putExtra("idZone", idZone);
                                                intent.putExtra("Element", editableElement.getText().toString());
                                                // per indicare a ModifyObject che fa parte del Modifica Luogo
                                                String dashboardFlag = "0";
                                                intent.putExtra("dashboardFlag", dashboardFlag);
                                                startActivity(intent);
                                                break;
                                            }
                                        }
                                    }
                                }
                            });
                        }
                    });
                }
            }
        }
    });
}
Also used : DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) Intent(android.content.Intent) List(java.util.List) TextView(android.widget.TextView) ElementString(com.example.alphatour.oggetti.ElementString) ElementString(com.example.alphatour.oggetti.ElementString) TextView(android.widget.TextView) View(android.view.View) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 3 with ElementString

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

the class ModifyObjectActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_modify_object);
    db = FirebaseFirestore.getInstance();
    storegeProfilePick = FirebaseStorage.getInstance().getReference();
    // riferimenti alle view
    title = findViewById(R.id.titleQr);
    description = findViewById(R.id.descriptionQr);
    photo = findViewById(R.id.changePhotoObjectQr);
    qrCode = findViewById(R.id.changeQr);
    imagePhoto = findViewById(R.id.photoQr);
    imageQrCode = findViewById(R.id.qr);
    typology = findViewById(R.id.inputTypeZoneQr);
    loadingBar = findViewById(R.id.modifyLoadingBar);
    loadingBar.setVisibility(View.VISIBLE);
    adapterItems = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, zoneList);
    Intent intent = getIntent();
    myQrData = intent.getStringExtra("data");
    Place = intent.getStringExtra("Place");
    idPlace = intent.getStringExtra("idPlace");
    Zone = intent.getStringExtra("Zone");
    idZone = intent.getStringExtra("idZone");
    Element = intent.getStringExtra("Element");
    dashboardFlag = intent.getStringExtra("dashboardFlag");
    // settaggio idPlace,idZone se si arriva da dashboard
    if (dashboardFlag.equals("1")) {
        getIdPlaceAndIdZone(myQrData);
    }
    // settaggio dati elemento
    db.collection("Elements").whereEqualTo("qrData", myQrData).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult() != null) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        ElementString element = document.toObject(ElementString.class);
                        idElement = document.getId();
                        db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if (task.isSuccessful()) {
                                    i++;
                                    for (QueryDocumentSnapshot document : task.getResult()) {
                                        Zone zone = document.toObject(Zone.class);
                                        if (i == 1 && zone.getIdPlace().equals(idPlace)) {
                                            zoneList.add(zone.getName());
                                            zoneMap.put(document.getId(), zone.getName());
                                        }
                                        if (document.getId().matches(element.getIdZone())) {
                                            zone = document.toObject(Zone.class);
                                            title.setText(element.getTitle());
                                            description.setText(element.getDescription());
                                            idPhotoAndQrCode = element.getIdPhotoAndQrCode();
                                            Qrdata = element.getQrData();
                                            showPhoto();
                                            showQrCode();
                                            typology.setAdapter(adapterItems);
                                            Zone = zone.getName();
                                            typology.setHint(Zone);
                                            typology.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                                                @Override
                                                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                                    typology.setError(null);
                                                    item = parent.getItemAtPosition(position).toString();
                                                }
                                            });
                                        }
                                    }
                                } else {
                                    Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto !!!", Toast.LENGTH_LONG).show();
                                    loadingBar.setVisibility(View.GONE);
                                }
                            }
                        });
                    }
                } else {
                    Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
                    loadingBar.setVisibility(View.GONE);
                    Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
                    startActivity(intent);
                }
            } else {
                Toast.makeText(ModifyObjectActivity.this, "Non è stato possibile caricare i dati dell'oggetto", Toast.LENGTH_LONG).show();
                loadingBar.setVisibility(View.GONE);
                Intent intent = new Intent(ModifyObjectActivity.this, DashboardActivity.class);
                startActivity(intent);
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(ModifyObjectActivity.this, "Oggetto non trovato !!!", Toast.LENGTH_LONG).show();
            loadingBar.setVisibility(View.GONE);
        }
    });
}
Also used : FileDownloadTask(com.google.firebase.storage.FileDownloadTask) UploadTask(com.google.firebase.storage.UploadTask) Task(com.google.android.gms.tasks.Task) StorageTask(com.google.firebase.storage.StorageTask) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Zone(com.example.alphatour.oggetti.Zone) Intent(android.content.Intent) ElementString(com.example.alphatour.oggetti.ElementString) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) IOException(java.io.IOException) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) NonNull(androidx.annotation.NonNull) AdapterView(android.widget.AdapterView) ElementString(com.example.alphatour.oggetti.ElementString) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 4 with ElementString

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

the class DashboardActivity method inputSearchClick.

private void inputSearchClick() {
    inputSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TourItem clickedItem = (TourItem) parent.getItemAtPosition(position);
            String clickedTourText = clickedItem.getTourText();
            db.collection("Elements").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    if (!queryDocumentSnapshots.isEmpty()) {
                        // lista elementi
                        List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                        for (DocumentSnapshot d : listDocument) {
                            ElementString element = d.toObject(ElementString.class);
                            if (clickedTourText.equals(element.getTitle())) {
                                Intent intent = new Intent(DashboardActivity.this, ModifyObjectActivity.class);
                                intent.putExtra("data", element.getQrData());
                                String dashboardFlag = "1";
                                intent.putExtra("dashboardFlag", dashboardFlag);
                                startActivity(intent);
                                inputSearch.setText(null);
                                break;
                            }
                        }
                    }
                }
            });
            db.collection("Zones").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) {
                            Zone zone = d.toObject(Zone.class);
                            if (clickedTourText.equals(zone.getName())) {
                                Intent intent = new Intent(DashboardActivity.this, ModifyZoneActivity.class);
                                intent.putExtra("idPlace", zone.getIdPlace());
                                intent.putExtra("Zone", zone.getName());
                                String dashboardFlag = "1";
                                intent.putExtra("dashboardFlag", dashboardFlag);
                                startActivity(intent);
                                inputSearch.setText(null);
                                break;
                            }
                        }
                    }
                }
            });
            db.collection("Places").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    if (!queryDocumentSnapshots.isEmpty()) {
                        // lista luoghi
                        List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                        for (DocumentSnapshot d : listDocument) {
                            Place place = d.toObject(Place.class);
                            if (clickedTourText.equals(place.getName())) {
                                Intent intent = new Intent(DashboardActivity.this, ModifyPlaceActivity.class);
                                intent.putExtra("Place", place.getName());
                                String dashboardFlag = "1";
                                intent.putExtra("dashboardFlag", dashboardFlag);
                                startActivity(intent);
                                inputSearch.setText(null);
                                break;
                            }
                        }
                    }
                }
            });
        }
    });
}
Also used : Zone(com.example.alphatour.oggetti.Zone) Intent(android.content.Intent) ElementString(com.example.alphatour.oggetti.ElementString) View(android.view.View) AdapterView(android.widget.AdapterView) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) TourItem(com.example.alphatour.oggetti.TourItem) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) AdapterView(android.widget.AdapterView) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) ElementString(com.example.alphatour.oggetti.ElementString) Place(com.example.alphatour.oggetti.Place)

Example 5 with ElementString

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

the class CreateConstraintsWizard method saveQrCode.

private void saveQrCode(Bitmap qrCode, Element element, int i, long id) {
    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(getContext(), "Zone e Oggetti creati con successo", Toast.LENGTH_LONG).show();
                                                    loadingBar.setVisibility(View.GONE);
                                                }
                                            }).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);
                                                }
                                            });
                                        }
                                    }
                                }
                            }
                        });
                    }
                }
            });
        }
    });
}
Also used : 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) 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) 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