Search in sources :

Example 1 with Zone

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

the class ImportPhotoObjectActivity method saveObjects.

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

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (int i = 0; i < elmlist.size(); i++) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        Element newElement = elmlist.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", newElement.getPhoto().toString());
                            elm.put("qrCode", null);
                            elm.put("idPhotoAndQrCode", Long.parseLong(newElement.getIdPhotoAndQrCodeString()));
                            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();
                                }
                            });
                            saveQrCode(newElement.getQrData(), newElement, i, id);
                        }
                    }
                }
            }
        }
    }).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();
        }
    });
}
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) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 2 with Zone

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

the class ImportPhotoObjectActivity 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(ImportPhotoObjectActivity.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)

Example 3 with Zone

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

the class ImportPhotoObjectActivity method readCsv.

private void readCsv(Intent data) {
    progressBar.setVisibility(View.VISIBLE);
    if (data == null) {
        return;
    } else {
        Uri uri = data.getData();
        Toast.makeText(ImportPhotoObjectActivity.this, uri.getPath(), Toast.LENGTH_SHORT).show();
        String path = uri.getPath();
        path = path.substring(path.indexOf(":") + 1);
        File file = new File(path);
        try {
            BufferedReader read = new BufferedReader(new FileReader(file));
            String line = "";
            Boolean isEmpty = true;
            while ((line = read.readLine()) != null) {
                isEmpty = false;
                String[] token = line.split(",");
                ReadCsv readCsv = new ReadCsv();
                boolean flag = false;
                for (int i = 0; i < token.length; i++) {
                    if (token[i] == null) {
                        flag = true;
                    }
                }
                if (!flag) {
                    if (!token[0].matches("namePlace")) {
                        Element elm = new Element();
                        Place place = new Place();
                        Zone zone = new Zone();
                        Constraint constraint = new Constraint();
                        if (listLineCsv.size() > 0) {
                            setDataToken(token, readCsv);
                            if (!token[0].isEmpty()) {
                                for (int i = 0; i < listPlace.size(); i++) {
                                    if (!listPlace.get(i).getName().matches(token[0]) && !listPlace.get(i).getCity().matches(token[1]) && !listPlace.get(i).getTypology().matches(token[2])) {
                                        idP++;
                                        place.setIdPlace(idP);
                                        place.setName(token[0]);
                                        place.setCity(token[1]);
                                        place.setTypology(token[2]);
                                        listPlace.add(place);
                                    }
                                }
                                for (int j = 0; j < listPlace.size(); j++) {
                                    if (!listZone.get(i).getName().matches(token[3])) {
                                        zone.setIdPl(idP);
                                        zone.setName(token[3]);
                                        idZ++;
                                        listZone.add(zone);
                                    }
                                }
                                elm.setIdZon(idZ);
                                elm.setTitle(readCsv.getTitleObject());
                                elm.setDescription(readCsv.getDescriptionObject());
                                elm.setQrData(readCsv.getQrDataObject());
                                elm.setPhoto(Uri.parse(readCsv.getLinkImageObject()));
                                String[] str = readCsv.getLinkImageObject().split("Objects_");
                                String[] st = str[1].split("\\?");
                                String idPh = st[0];
                                elm.setIdPhotoAndQrCodeString(idPh);
                                elm.setZoneRif(token[3]);
                                if (!token[8].isEmpty() && !!token[9].isEmpty()) {
                                    constraint.setFromZone(token[8]);
                                    constraint.setInZone(token[9]);
                                }
                                listElement.add(elm);
                                if (!token[8].isEmpty() && !token[9].isEmpty()) {
                                    constraint.setFromZone(token[8]);
                                    constraint.setInZone(token[9]);
                                    listConstranints.add(constraint);
                                }
                            }
                        } else {
                            setDataToken(token, readCsv);
                            if (!token[0].isEmpty()) {
                                elm.setTitle(readCsv.getTitleObject());
                                elm.setDescription(readCsv.getDescriptionObject());
                                elm.setQrData(readCsv.getQrDataObject());
                                elm.setPhoto(Uri.parse(readCsv.getLinkImageObject()));
                                String[] str = readCsv.getLinkImageObject().split("Objects_");
                                String[] st = str[1].split("\\?");
                                String idPh = st[0];
                                elm.setIdPhotoAndQrCodeString(idPh);
                                elm.setZoneRif(token[3]);
                                place.setName(token[0]);
                                place.setCity(token[1]);
                                place.setTypology(token[2]);
                                place.setIdPlace(idP);
                                zone.setIdPl(idP);
                                zone.setName(token[3]);
                                elm.setIdZon(idZ);
                                listPlace.add(place);
                                listZone.add(zone);
                                listElement.add(elm);
                            }
                            if (!token[8].isEmpty() && !token[9].isEmpty()) {
                                constraint.setFromZone(token[8]);
                                constraint.setInZone(token[9]);
                                listConstranints.add(constraint);
                            }
                        }
                    }
                } else {
                    Toast.makeText(ImportPhotoObjectActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
                    line = null;
                    progressBar.setVisibility(View.GONE);
                }
            }
            if (isEmpty) {
                Toast.makeText(ImportPhotoObjectActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
                progressBar.setVisibility(View.GONE);
            } else {
                savePlace();
                saveConstraints();
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (success) {
                            Intent intent = new Intent(ImportPhotoObjectActivity.this, DashboardActivity.class);
                            startActivity(intent);
                            progressBar.setVisibility(View.GONE);
                        } else {
                            Toast.makeText(ImportPhotoObjectActivity.this, "Salvataggio Luogo non riuscito", Toast.LENGTH_LONG).show();
                            progressBar.setVisibility(View.GONE);
                        }
                    }
                }, 2000L);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Constraint(com.example.alphatour.oggetti.Constraint) Zone(com.example.alphatour.oggetti.Zone) Element(com.example.alphatour.oggetti.Element) FileNotFoundException(java.io.FileNotFoundException) Handler(android.os.Handler) Intent(android.content.Intent) ElementString(com.example.alphatour.oggetti.ElementString) IOException(java.io.IOException) Uri(android.net.Uri) Constraint(com.example.alphatour.oggetti.Constraint) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) Place(com.example.alphatour.oggetti.Place)

Example 4 with Zone

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

the class ListZonesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_zones);
    // 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");
    dashboardFlag = intent.getStringExtra("dashboardFlag");
    placeText = findViewById(R.id.specificPlaceText);
    placeText.setText(Place);
    layout_list = findViewById(R.id.listZonesLayout);
    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);
                    final View zoneView = getLayoutInflater().inflate(R.layout.row_update, null, false);
                    TextView editableZone = (TextView) zoneView.findViewById(R.id.itemUpdateText);
                    editableZone.setText(zone.getName());
                    layout_list.addView(zoneView);
                    editableZone.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View zoneView) {
                            Intent intent = new Intent(ListZonesActivity.this, ModifyZoneActivity.class);
                            intent.putExtra("Place", Place);
                            intent.putExtra("idPlace", idPlace);
                            intent.putExtra("Zone", editableZone.getText().toString());
                            // per indicare a ModifyZone che fa parte del Modifica Luogo
                            String dashboardFlag = "0";
                            intent.putExtra("dashboardFlag", dashboardFlag);
                            startActivity(intent);
                        }
                    });
                }
            }
        }
    });
}
Also used : DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) Zone(com.example.alphatour.oggetti.Zone) Intent(android.content.Intent) List(java.util.List) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 5 with Zone

use of com.example.alphatour.oggetti.Zone 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)

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