Search in sources :

Example 1 with CheckableTextView

use of com.devzone.checkabletextview.CheckableTextView 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 2 with CheckableTextView

use of com.devzone.checkabletextview.CheckableTextView in project AlphaTour by Frank99DG.

the class Step3 method setUserVisibleHint.

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);
    if (isVisibleToUser) {
        zone_selected.setText(DashboardActivity.getZona_scelta());
        String scelta = DashboardActivity.getZona_scelta();
        db.collection("Zones").whereEqualTo("name", scelta).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()) {
                    for (QueryDocumentSnapshot document : task.getResult()) {
                        String idZone = document.getId();
                        db.collection("Elements").whereEqualTo("idZone", idZone).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                            @Override
                            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                                if (task.isSuccessful()) {
                                    for (QueryDocumentSnapshot document : task.getResult()) {
                                        ElementString element = document.toObject(ElementString.class);
                                        View object = getLayoutInflater().inflate(R.layout.row_selection_zones_elements, null, false);
                                        CheckableTextView textZone1 = (CheckableTextView) object.findViewById(R.id.textObjectss);
                                        textZone1.setText(element.getTitle());
                                        arrayStringElement.add(element.getTitle());
                                        // arrayObjectElement.add(element);
                                        arrayMonumenti.add(textZone1);
                                        delete_view.add(object);
                                        list_object.addView(object);
                                    }
                                } else {
                                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                    }
                } else {
                    Toast.makeText(getContext(), "Non è stato possibile caricare le zone !!!", Toast.LENGTH_LONG).show();
                }
            }
        });
    } else {
    }
}
Also used : OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) CheckableTextView(com.devzone.checkabletextview.CheckableTextView) NonNull(androidx.annotation.NonNull) ElementString(com.example.alphatour.oggetti.ElementString) 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)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 CheckableTextView (com.devzone.checkabletextview.CheckableTextView)2 ElementString (com.example.alphatour.oggetti.ElementString)2 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)2 CheckedListener (com.devzone.checkabletextview.CheckedListener)1 Constraint (com.example.alphatour.oggetti.Constraint)1 Zone (com.example.alphatour.oggetti.Zone)1 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)1 OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)1 Task (com.google.android.gms.tasks.Task)1 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)1 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1