Search in sources :

Example 6 with Element

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

the class FileReceiverActivity 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(FileReceiverActivity.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 7 with Element

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

the class FileReceiverActivity method readCsv.

private void readCsv(Intent data) {
    if (data == null) {
        return;
    } else {
        Uri uri = data.getParcelableExtra(Intent.EXTRA_STREAM);
        Toast.makeText(FileReceiverActivity.this, uri.getPath(), Toast.LENGTH_SHORT).show();
        String path = uri.getPath();
        String filename = URLUtil.guessFileName(path, null, null);
        String downloadPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
        path = path.substring(path.lastIndexOf('/') + 1);
        File file = new File(downloadPath, filename);
        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(FileReceiverActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
                    line = null;
                }
            }
            if (isEmpty) {
                Toast.makeText(FileReceiverActivity.this, "Errore duratnte l'importazione del file, alcuni" + "campi potrebbero essere vuoti", Toast.LENGTH_LONG).show();
            } else {
                savePlace();
                saveConstraints();
                new Handler().postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        if (success) {
                            Intent intent = new Intent(FileReceiverActivity.this, DashboardActivity.class);
                            startActivity(intent);
                            progressBar.setVisibility(View.GONE);
                        } else {
                            Toast.makeText(FileReceiverActivity.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) ReadCsv(com.example.alphatour.ReadCsv) Constraint(com.example.alphatour.oggetti.Constraint) BufferedReader(java.io.BufferedReader) DashboardActivity(com.example.alphatour.DashboardActivity) FileReader(java.io.FileReader) File(java.io.File) Place(com.example.alphatour.oggetti.Place)

Example 8 with Element

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

the class CreateConstraintsWizard method saveObjectsLocal.

private long saveObjectsLocal(List<Element> elementList) {
    long newRowId = -1;
    AlphaTourDbHelper dbAlpha = new AlphaTourDbHelper(getContext());
    SQLiteDatabase db = dbAlpha.getWritableDatabase();
    ContentValues values = new ContentValues();
    for (int i = 0; i < elementList.size(); i++) {
        Element elm = elementList.get(i);
        String idZone = getIdZone(elm);
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_ID_ZONE, idZone);
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_NAME, elm.getTitle());
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_DESCRIPTION, elm.getDescription());
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_PHOTO, elm.getPhoto().toString());
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_QR_CODE, elm.getQrData());
        values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_ELEMENT_LOAD, load);
        newRowId = db.insert(AlphaTourContract.AlphaTourEntry.NAME_TABLE_ELEMENT, AlphaTourContract.AlphaTourEntry.COLUMN_NAME_NULLABLE, values);
    }
    return newRowId;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Element(com.example.alphatour.oggetti.Element) AlphaTourDbHelper(com.example.alphatour.dblite.AlphaTourDbHelper) ElementString(com.example.alphatour.oggetti.ElementString) Constraint(com.example.alphatour.oggetti.Constraint)

Example 9 with Element

use of com.example.alphatour.oggetti.Element 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 10 with Element

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

the class CreateObjectWizard method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 10) {
        if (data != null) {
            created = true;
            Element element = new Element();
            element.setTitle(data.getStringExtra("title"));
            element.setDescription(data.getStringExtra("description"));
            element.setQrData(data.getStringExtra("data"));
            zone = data.getStringExtra("zone");
            element.setZoneRif(zone);
            setPh(AddElementActivity.getPhoto());
            setQr(AddElementActivity.getQr());
            createdObject(element);
        }
    } else {
        if (data != null) {
            created = true;
            Element element = new Element();
            element.setTitle(data.getStringExtra("title"));
            element.setDescription(data.getStringExtra("description"));
            element.setQrData(data.getStringExtra("data"));
            zone = data.getStringExtra("zone");
            element.setZoneRif(zone);
            setPh(ElementDetailsActivity.getPh());
            setQr(ElementDetailsActivity.getQr());
            createdObject(element);
        }
    }
}
Also used : Element(com.example.alphatour.oggetti.Element)

Aggregations

Element (com.example.alphatour.oggetti.Element)10 Constraint (com.example.alphatour.oggetti.Constraint)6 Zone (com.example.alphatour.oggetti.Zone)5 Intent (android.content.Intent)4 ElementString (com.example.alphatour.oggetti.ElementString)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 NonNull (androidx.annotation.NonNull)3 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)3 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)3 Task (com.google.android.gms.tasks.Task)3 DocumentReference (com.google.firebase.firestore.DocumentReference)3 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)3 StorageTask (com.google.firebase.storage.StorageTask)3 UploadTask (com.google.firebase.storage.UploadTask)3 Uri (android.net.Uri)2 Handler (android.os.Handler)2 Place (com.example.alphatour.oggetti.Place)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2