Search in sources :

Example 1 with Element

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

the class AddElementActivity method saveObject.

public void saveObject(View v) {
    element = new Element();
    String Title = nameElement.getText().toString();
    String Description = description.getText().toString();
    if (Title.isEmpty()) {
        nameElement.setError(getString(R.string.required_field));
        nameElement.requestFocus();
        errorFlag = true;
    } else {
        element.setTitle(Title);
        errorFlag = false;
    }
    if (Description.isEmpty()) {
        description.setError(getString(R.string.required_field));
        description.requestFocus();
        errorFlag = true;
    } else {
        element.setDescription(Description);
        errorFlag = false;
    }
    if (flagPhoto == false) {
        if (permission) {
            photo.setError(getString(R.string.required_field));
            photo.requestFocus();
            errorFlag = true;
        } else {
            uri = Uri.parse("");
            setPhoto(uri);
            element.setPhoto(uri);
        }
    } else {
        if (uri != null) {
            element.setPhoto(uri);
            setPhoto(uri);
            errorFlag = false;
        }
    }
    if (GenerateQrCodeActivity.getQrFlag() == false) {
        generateQrCode.setError(getString(R.string.required_field));
        generateQrCode.requestFocus();
        errorFlag = true;
    } else {
        element.setQrCode(GenerateQrCodeActivity.getBitmap());
        setQr(GenerateQrCodeActivity.getBitmap());
        errorFlag = false;
    }
    if (errorFlag) {
        return;
    } else {
        if (!duplicateControl(Title)) {
            Intent intent = new Intent();
            intent.putExtra("title", element.getTitle());
            intent.putExtra("description", element.getDescription());
            intent.putExtra("data", GenerateQrCodeActivity.getData());
            Bundle bundle;
            intent.putExtra("zone", item);
            setResult(Activity.RESULT_OK, intent);
            finish();
        } else {
            Toast.makeText(AddElementActivity.this, R.string.object_already_exists, Toast.LENGTH_LONG).show();
        }
    }
}
Also used : Bundle(android.os.Bundle) Element(com.example.alphatour.oggetti.Element) Intent(android.content.Intent) ElementString(com.example.alphatour.oggetti.ElementString)

Example 2 with Element

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

the class ElementDetailsActivity method saveElement.

public void saveElement(View view) {
    save = true;
    String Title = title.getText().toString();
    String Description = description.getText().toString();
    // String Activity = activity.getText().toString();
    Element elementModified = new Element();
    if (Title.isEmpty()) {
        title.setError(getString(R.string.required_field));
        title.requestFocus();
        errorFlag = true;
    } else {
        elementModified.setTitle(Title);
    }
    if (Description.isEmpty()) {
        description.setError(getString(R.string.required_field));
        description.requestFocus();
        errorFlag = true;
    } else {
        elementModified.setDescription(Description);
    }
    if (errorFlag) {
        return;
    } else {
        Intent intent = new Intent();
        intent.putExtra("title", elementModified.getTitle());
        intent.putExtra("description", elementModified.getDescription());
        if (selected) {
            intent.putExtra("zone", item);
        } else {
            intent.putExtra("zone", zone);
        }
        setResult(Activity.RESULT_OK, intent);
        View v = list.get(0);
        LinearLayout layout = CreateObjectWizard.getLayout_list();
        for (int i = 0; i < elementList.size(); i++) {
            if (elementList.get(i).equals(element)) {
                elementList.remove(i);
                CreateObjectWizard.setElementList(elementList);
            }
        }
        layout.removeView(v);
        list.remove(0);
        finish();
    }
}
Also used : Element(com.example.alphatour.oggetti.Element) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 3 with Element

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

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

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

the class CreateObjectWizard method LoadPreferences.

private void LoadPreferences() {
    SharedPreferences sharedPreferences = getActivity().getPreferences(Context.MODE_PRIVATE);
    int size = sharedPreferences.getInt("elementListSize", 0);
    elementList.clear();
    for (int i = 0; i < size; i++) {
        created = true;
        Element element = new Element();
        element.setSaved(sharedPreferences.getBoolean("Saved" + i, true));
        element.setZoneRif(sharedPreferences.getString("Zone" + i, ""));
        element.setTitle(sharedPreferences.getString("Title" + i, ""));
        element.setDescription(sharedPreferences.getString("Description" + i, ""));
        element.setPhoto(Uri.parse(sharedPreferences.getString("Photo" + i, "")));
        element.setQrData(sharedPreferences.getString("QrData" + i, ""));
        Bitmap bitmap = convertStringToBitmap(sharedPreferences.getString("QrCode" + i, ""));
        element.setQrCode(bitmap);
        createdObject(element);
    }
}
Also used : Bitmap(android.graphics.Bitmap) SharedPreferences(android.content.SharedPreferences) 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