Search in sources :

Example 1 with Place

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

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

the class ModifyPlaceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_modify_place);
    db = FirebaseFirestore.getInstance();
    auth = FirebaseAuth.getInstance();
    user = auth.getCurrentUser();
    idUser = user.getUid();
    Intent intent = getIntent();
    Place = intent.getStringExtra("Place");
    getIdPlace(Place);
    dashboardFlag = intent.getStringExtra("dashboardFlag");
    placeText = findViewById(R.id.myPlaceText);
    namePlace = findViewById(R.id.updateNamePlace);
    city = findViewById(R.id.updateCityPlace);
    typology = findViewById(R.id.updateTypologyPlace);
    typology_list.add(getString(R.string.museum));
    typology_list.add(getString(R.string.fair));
    typology_list.add(getString(R.string.archaeological_site));
    typology_list.add(getString(R.string.museum_exhibition));
    adapterItems = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, typology_list);
    typology.setAdapter(adapterItems);
    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();
        }
    });
    loadingBar = findViewById(R.id.modifyPlaceLoadingBar);
    db.collection("Places").whereEqualTo("idUser", idUser).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
            if (!queryDocumentSnapshots.isEmpty()) {
                List<DocumentSnapshot> listDocuments = queryDocumentSnapshots.getDocuments();
                for (DocumentSnapshot d : listDocuments) {
                    Place place = d.toObject(Place.class);
                    if (Place.equals(place.getName())) {
                        placeText.setText(place.getName());
                        namePlace.setText(place.getName());
                        city.setText(place.getCity());
                        typology.setText(place.getTypology());
                        break;
                    }
                }
            }
        }
    });
}
Also used : Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) AdapterView(android.widget.AdapterView) ArrayList(java.util.ArrayList) List(java.util.List) Place(com.example.alphatour.oggetti.Place)

Example 3 with Place

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

the class CreateConstraintsWizard method savePlace.

private void savePlace() {
    Place place = new Place(CreatePlaceWizard.getNamePlace(), CreatePlaceWizard.getCity(), CreatePlaceWizard.getTypology(), user.getUid());
    db.collection("Places").add(place).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

        @Override
        public void onSuccess(DocumentReference documentReference) {
            idPlace = documentReference.getId();
            saveZones(CreateZoneWizard.getZone_list());
            success = true;
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(getContext(), "Salvataggio Luogo non riuscito", Toast.LENGTH_LONG).show();
            loadingBar.setVisibility(View.GONE);
        }
    });
}
Also used : OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) Place(com.example.alphatour.oggetti.Place) DocumentReference(com.google.firebase.firestore.DocumentReference) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 4 with Place

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

the class CreateConstraintsWizard method saveZonesAndConstraintInGraph.

public void saveZonesAndConstraintInGraph() {
    Graph<Zone, DefaultEdge> zones = new SimpleDirectedGraph<>(DefaultEdge.class);
    for (String nameZone : zone_list) {
        Zone zone = new Zone(nameZone);
        zones.addVertex(zone);
    }
    /*for (List list : all_link_lists){
            for (String  : list){
                zones.addEdge( , );

            }
        }*/
    Place place = new Place("NewTopMuseum", "Bari", "Museo", "1");
    Log.i("Luogo creato:", place.toString());
}
Also used : Zone(com.example.alphatour.oggetti.Zone) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph) DefaultEdge(org.jgrapht.graph.DefaultEdge) ElementString(com.example.alphatour.oggetti.ElementString) Place(com.example.alphatour.oggetti.Place)

Example 5 with Place

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

the class FileReceiverActivity method savePlace.

private void savePlace() {
    for (i = 0; i < listPlace.size(); i++) {
        Place place = new Place(listPlace.get(i).getName(), listPlace.get(i).getCity(), listPlace.get(i).getTypology(), user.getUid());
        db.collection("Places").add(place).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

            @Override
            public void onSuccess(DocumentReference documentReference) {
                idPlace = documentReference.getId();
                saveZones(listZone, listPlace.get(i - 1).getIdPlace());
                success = true;
            }
        }).addOnFailureListener(new OnFailureListener() {

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

Aggregations

Place (com.example.alphatour.oggetti.Place)9 Intent (android.content.Intent)5 ElementString (com.example.alphatour.oggetti.ElementString)4 Zone (com.example.alphatour.oggetti.Zone)4 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 View (android.view.View)3 TextView (android.widget.TextView)3 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)3 DocumentReference (com.google.firebase.firestore.DocumentReference)3 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)3 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)3 Uri (android.net.Uri)2 Handler (android.os.Handler)2 AdapterView (android.widget.AdapterView)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Constraint (com.example.alphatour.oggetti.Constraint)2 Element (com.example.alphatour.oggetti.Element)2 BufferedReader (java.io.BufferedReader)2