Search in sources :

Example 21 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirebaseUI-Android by firebase.

the class FirestoreArray method onDocumentModified.

private void onDocumentModified(DocumentChange change) {
    QueryDocumentSnapshot snapshot = change.getDocument();
    if (change.getOldIndex() == change.getNewIndex()) {
        // Document modified only
        mSnapshots.set(change.getNewIndex(), snapshot);
        notifyOnChildChanged(ChangeEventType.CHANGED, snapshot, change.getNewIndex(), change.getNewIndex());
    } else {
        // Document moved and possibly also modified
        mSnapshots.remove(change.getOldIndex());
        mSnapshots.add(change.getNewIndex(), snapshot);
        notifyOnChildChanged(ChangeEventType.MOVED, snapshot, change.getNewIndex(), change.getOldIndex());
        notifyOnChildChanged(ChangeEventType.CHANGED, snapshot, change.getNewIndex(), change.getNewIndex());
    }
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Example 22 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Chat-app by TuTuanLe.

the class ChatFragment method getUSer.

private void getUSer() {
    loading(true);
    FirebaseFirestore database = FirebaseFirestore.getInstance();
    database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
        loading(false);
        String currentUserId = preferenceManager.getString(Constants.KEY_USER_ID);
        if (task.isSuccessful() && task.getResult() != null) {
            List<User> users = new ArrayList<>();
            for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
                if (currentUserId.equals(queryDocumentSnapshot.getId())) {
                    continue;
                }
                User user = new User();
                user.setName(queryDocumentSnapshot.getString(Constants.KEY_NAME));
                user.setEmail(queryDocumentSnapshot.getString(Constants.KEY_EMAIL));
                user.setProfileImage(queryDocumentSnapshot.getString(Constants.KEY_IMAGE));
                user.setToken(queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN));
                user.setUid(queryDocumentSnapshot.getId());
                user.setAvailability(queryDocumentSnapshot.getLong(Constants.KEY_AVAILABILITY));
                users.add(user);
            }
            if (users.size() > 0) {
                Users_Adapter users_adapter = new Users_Adapter(users, mainScreenActivity);
                RecyclerView temp = view.findViewById(R.id.userRecyclerView);
                temp.setAdapter(users_adapter);
                temp.setVisibility(View.VISIBLE);
            } else {
                showErrorMessage();
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.tutuanle.chatapp.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) Users_Adapter(com.tutuanle.chatapp.adapters.Users_Adapter) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 23 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Chat-app by TuTuanLe.

the class SearchActivity method getUSer.

private void getUSer() {
    loading(true);
    FirebaseFirestore database = FirebaseFirestore.getInstance();
    database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
        loading(false);
        String currentUserId = preferenceManager.getString(Constants.KEY_USER_ID);
        if (task.isSuccessful() && task.getResult() != null) {
            users = new ArrayList<>();
            for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
                if (currentUserId.equals(queryDocumentSnapshot.getId())) {
                    continue;
                }
                User user = new User();
                user.setName(queryDocumentSnapshot.getString(Constants.KEY_NAME));
                user.setEmail(queryDocumentSnapshot.getString(Constants.KEY_EMAIL));
                user.setProfileImage(queryDocumentSnapshot.getString(Constants.KEY_IMAGE));
                user.setToken(queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN));
                user.setUid(queryDocumentSnapshot.getId());
                user.setAvailability(queryDocumentSnapshot.getLong(Constants.KEY_AVAILABILITY));
                users.add(user);
            }
            if (users.size() > 0) {
                searchAdapter = new SearchAdapter(users, SearchActivity.this);
                binding.userRecyclerView.setAdapter(searchAdapter);
                binding.userRecyclerView.setVisibility(View.VISIBLE);
            } else {
                showToast("Error");
            }
        }
    });
}
Also used : FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.tutuanle.chatapp.models.User) SearchAdapter(com.tutuanle.chatapp.adapters.SearchAdapter) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Example 24 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot 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 25 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot 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

QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)73 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)33 ArrayList (java.util.ArrayList)30 View (android.view.View)22 NonNull (androidx.annotation.NonNull)19 Task (com.google.android.gms.tasks.Task)18 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)17 Intent (android.content.Intent)16 CollectionReference (com.google.firebase.firestore.CollectionReference)13 AdapterView (android.widget.AdapterView)12 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)12 TextView (android.widget.TextView)10 Bundle (android.os.Bundle)9 ListView (android.widget.ListView)9 DocumentSnapshot (com.google.firebase.firestore.DocumentSnapshot)9 FirebaseFirestoreException (com.google.firebase.firestore.FirebaseFirestoreException)8 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)7 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)6 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 DocumentReference (com.google.firebase.firestore.DocumentReference)6