Search in sources :

Example 11 with Zone

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

the class ModifyZoneActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_modify_zone);
    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");
    getIdZone(Zone);
    dashboardFlag = intent.getStringExtra("dashboardFlag");
    // settaggio Place se si arriva da dashboard
    if (dashboardFlag.equals("1")) {
        getPlace(idPlace);
    }
    zoneText = findViewById(R.id.myZoneText);
    nameZone = findViewById(R.id.updateNameZone);
    loadingBar = findViewById(R.id.modifyZoneLoadingBar);
    db.collection("Zones").whereEqualTo("idPlace", idPlace).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
            if (!queryDocumentSnapshots.isEmpty()) {
                List<DocumentSnapshot> listDocuments = queryDocumentSnapshots.getDocuments();
                for (DocumentSnapshot d : listDocuments) {
                    Zone zone = d.toObject(Zone.class);
                    if (Zone.equals(zone.getName())) {
                        zoneText.setText(zone.getName());
                        nameZone.setText(zone.getName());
                        break;
                    }
                }
            }
        }
    });
}
Also used : DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) Zone(com.example.alphatour.oggetti.Zone) Intent(android.content.Intent) ArrayList(java.util.ArrayList) List(java.util.List) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 12 with Zone

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

the class CreateConstraintsWizard method saveObjects.

/*public boolean inputControl(String Prova){

        Boolean errorFlag = false;

        if (Prova.isEmpty()) {
            prova.setError(getString(R.string.campo_obbligatorio));
            prova.requestFocus();
            errorFlag = true;
        }

        return errorFlag;

    }*/
private void saveObjects(List<Element> elementlist) {
    db.collection("Zones").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (int i = 0; i < elementlist.size(); i++) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Element newElement = elementlist.get(i);
                        Zone zon = document.toObject(Zone.class);
                        if (zon.getName().matches(newElement.getZoneRif())) {
                            newElement.setIdZone(document.getId());
                            id = generateidPhotoAndQrCode();
                            elm.put("idZone", newElement.getIdZone());
                            elm.put("title", newElement.getTitle());
                            elm.put("description", newElement.getDescription());
                            elm.put("photo", null);
                            elm.put("qrCode", null);
                            elm.put("idPhotoAndQrCode", id);
                            elm.put("idUser", user.getUid());
                            elm.put("qrData", newElement.getQrData());
                            db.collection("Elements").add(elm).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

                                @Override
                                public void onSuccess(DocumentReference documentReference) {
                                    success = true;
                                // String id=documentReference.getId();
                                }
                            });
                            savePhoto(newElement.getPhoto(), newElement, i, id);
                            saveQrCode(newElement.getQrCode(), newElement, i, id);
                        }
                    }
                }
            }
        }
    }).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();
        }
    });
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) 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) NonNull(androidx.annotation.NonNull) Element(com.example.alphatour.oggetti.Element) Constraint(com.example.alphatour.oggetti.Constraint) DocumentReference(com.google.firebase.firestore.DocumentReference) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 13 with Zone

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

the class Step2 method getZones.

public void getZones() {
    loadingbar.setVisibility(View.VISIBLE);
    if (!receiver.isConnected()) {
    }
    db.collection("Zones").whereEqualTo("idUser", user.getUid()).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
            if (!queryDocumentSnapshots.isEmpty()) {
                // lista zone
                List<DocumentSnapshot> listDocument = queryDocumentSnapshots.getDocuments();
                if (!DashboardActivity.isFirstZoneChosen()) {
                    for (DocumentSnapshot d : listDocument) {
                        Zone zone = d.toObject(Zone.class);
                        if (idPlace.matches(zone.getIdPlace())) {
                            View zoneView = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
                            CheckableTextView textZone1 = (CheckableTextView) zoneView.findViewById(R.id.textObjectss);
                            textZone1.setText(zone.getName());
                            array_database.add(zone.getName());
                            arrayZone.add(textZone1);
                            list_zone.addView(zoneView);
                            deleteView.add(zoneView);
                        }
                    }
                    for (i = 0; i < arrayZone.size(); i++) {
                        arrayZone.get(i).setOnCheckChangeListener(new CheckedListener() {

                            @Override
                            public void onCheckChange(@NonNull View view, boolean b) {
                                // contatore per capire quando ne seleziona 2
                                int c = 0;
                                for (int a = 0; a < arrayZone.size(); a++) {
                                    // ciclo per contare quanti sono checkati
                                    if (arrayZone.get(a).isChecked()) {
                                        c++;
                                    }
                                }
                                for (int j = 0; j < arrayZone.size(); j++) {
                                    // se è checkato più di uno, il precedente che è checkato viene impostato a false
                                    if (c > 1) {
                                        if (n == j) {
                                            arrayZone.get(j).setChecked(false, false);
                                        }
                                    }
                                }
                                for (int k = 0; k < arrayZone.size(); k++) {
                                    // serve per tenere la posizione dell'ultimo checkato
                                    if (arrayZone.get(k).isChecked()) {
                                        n = k;
                                        continue;
                                    }
                                }
                            }
                        });
                    }
                } else {
                    db.collection("Constraints").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

                        @Override
                        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                            List<DocumentSnapshot> listConstraint = queryDocumentSnapshots.getDocuments();
                            for (DocumentSnapshot d : listConstraint) {
                                Constraint constraint = d.toObject(Constraint.class);
                                String zona;
                                if (PercorsoWizard.isZonePassFromReview()) {
                                    zona = PercorsoWizard.getZone();
                                    DashboardActivity.setZona_vecchia(zona);
                                    DashboardActivity.setZona_scelta(zona);
                                } else {
                                    zona = DashboardActivity.getZona_scelta();
                                    DashboardActivity.setZona_vecchia(zona);
                                }
                                if (constraint.getFromZone().matches(zona)) {
                                    View zone = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
                                    CheckableTextView textZone1 = (CheckableTextView) zone.findViewById(R.id.textObjectss);
                                    textZone1.setText(constraint.getInZone());
                                    array_database.add(constraint.getInZone());
                                    arrayZone.add(textZone1);
                                    list_zone.addView(zone);
                                    deleteView.add(zone);
                                }
                            }
                            PercorsoWizard.setZonePassFromReview(false);
                            for (i = 0; i < arrayZone.size(); i++) {
                                arrayZone.get(i).setOnCheckChangeListener(new CheckedListener() {

                                    @Override
                                    public void onCheckChange(@NonNull View view, boolean b) {
                                        // contatore per capire quando ne seleziona 2
                                        int c = 0;
                                        for (int a = 0; a < arrayZone.size(); a++) {
                                            // ciclo per contare quanti sono checkati
                                            if (arrayZone.get(a).isChecked()) {
                                                c++;
                                            }
                                        }
                                        for (int j = 0; j < arrayZone.size(); j++) {
                                            // se è checkato più di uno, il precedente che è checkato viene impostato a false
                                            if (c > 1) {
                                                if (n == j) {
                                                    arrayZone.get(j).setChecked(false, false);
                                                }
                                            }
                                        }
                                        for (int k = 0; k < arrayZone.size(); k++) {
                                            // serve per tenere la posizione dell'ultimo checkato
                                            if (arrayZone.get(k).isChecked()) {
                                                n = k;
                                                continue;
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
                loadingbar.setVisibility(View.GONE);
            }
        }
    });
}
Also used : CheckableTextView(com.devzone.checkabletextview.CheckableTextView) Constraint(com.example.alphatour.oggetti.Constraint) Zone(com.example.alphatour.oggetti.Zone) 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) Constraint(com.example.alphatour.oggetti.Constraint) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) CheckedListener(com.devzone.checkabletextview.CheckedListener) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener)

Example 14 with Zone

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

the class FileReceiverActivity method saveZones.

private void saveZones(List<Zone> zone_list, int idPlac) {
    for (i = 0; i < zone_list.size(); i++) {
        if (listZone.get(i).getIdPl() == idPlac) {
            Zone zone = new Zone(zone_list.get(i).getName(), this.idPlace, null, user.getUid());
            db.collection("Zones").add(zone).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

                @Override
                public void onSuccess(DocumentReference documentReference) {
                    if (i == zone_list.size() && flag1 == false) {
                        flag1 = true;
                        saveObjects(listElement);
                    }
                    success = true;
                }
            }).addOnFailureListener(new OnFailureListener() {

                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(FileReceiverActivity.this, "Salvataggio Zone non riuscito", Toast.LENGTH_LONG).show();
                }
            });
        }
    }
}
Also used : Zone(com.example.alphatour.oggetti.Zone) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) DocumentReference(com.google.firebase.firestore.DocumentReference) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

Zone (com.example.alphatour.oggetti.Zone)14 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)7 IOException (java.io.IOException)7 Intent (android.content.Intent)6 Constraint (com.example.alphatour.oggetti.Constraint)6 ElementString (com.example.alphatour.oggetti.ElementString)6 DocumentReference (com.google.firebase.firestore.DocumentReference)6 FileNotFoundException (java.io.FileNotFoundException)6 NonNull (androidx.annotation.NonNull)5 Element (com.example.alphatour.oggetti.Element)5 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)5 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)5 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)5 View (android.view.View)4 Place (com.example.alphatour.oggetti.Place)4 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)4 Task (com.google.android.gms.tasks.Task)4 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)4 StorageTask (com.google.firebase.storage.StorageTask)4 UploadTask (com.google.firebase.storage.UploadTask)4