Search in sources :

Example 6 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project EZMeal by Jake-Sokol2.

the class GroupListsViewModel method fillShoppingList.

public List<List<String>> fillShoppingList() {
    // String currentListName = groupList.get(getCurrentSelected());
    String currentListName = "Tristan";
    List<List<String>> tmpListOfLists = new ArrayList<>();
    String email = mAuth.getCurrentUser().getEmail();
    db.collection("Groups").whereEqualTo("ListName", currentListName).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult().getDocuments().size() > 0) {
                    DocumentSnapshot tmpDoc = task.getResult().getDocuments().get(0);
                    String tmpDocName = tmpDoc.getId();
                    CollectionReference dbShoppingList = db.collection("Groups").document(tmpDocName).collection("Items");
                    dbShoppingList.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<QuerySnapshot> task) {
                            if (task.isSuccessful()) {
                                for (QueryDocumentSnapshot docBoi : task.getResult()) {
                                    List<String> tmpList = new ArrayList<>();
                                    brandName = docBoi.getString("brand");
                                    itemName = docBoi.getString("name");
                                    tmpList.add(itemName);
                                    tmpList.add(brandName);
                                    tmpList.add("1");
                                    tmpListOfLists.add(tmpList);
                                }
                                Log.i("Query", "Finished filling shopping list");
                            }
                        }
                    });
                }
            }
        }
    });
    return tmpListOfLists;
}
Also used : Task(com.google.android.gms.tasks.Task) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) CollectionReference(com.google.firebase.firestore.CollectionReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project EZMeal by Jake-Sokol2.

the class GroupListsViewModel method removeItem.

public void removeItem(int position) {
    List<List<String>> tmp = new ArrayList<List<String>>();
    tmp = shoppingList.getValue();
    itemName = tmp.get(position).get(0);
    brandName = tmp.get(position).get(1);
    tmp.remove(position);
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser mCurrentUser = mAuth.getCurrentUser();
    String email = mCurrentUser.getEmail();
    CollectionReference dbItems = db.collection("Items");
    dbItems.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Log.d("Hoyah", document.getId() + " => " + document.getData());
                    if (Objects.equals(itemName, document.getString("name")) && Objects.equals(document.getString("user"), email)) {
                        docID = document.getId();
                        dbItems.document(docID).delete();
                    }
                // end if
                }
            // end for loop
            }
        // end task successful
        }
    });
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FirebaseUser(com.google.firebase.auth.FirebaseUser) CollectionReference(com.google.firebase.firestore.CollectionReference) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot)

Example 8 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Skool by NhatTruongK15.

the class GroupChatActivity method getUsers.

private void getUsers() {
    loading(true);
    FirebaseFirestore database = FirebaseFirestore.getInstance();
    database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
        loading(false);
        String currentUserId = preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_ID);
        if (task.isSuccessful() && task.getResult() != null) {
            for (QueryDocumentSnapshot queryDocumentSnapshot : task.getResult()) {
                if (currentUserId.equals(queryDocumentSnapshot.getId())) {
                    continue;
                }
                User user = new User();
                user.name = queryDocumentSnapshot.getString(Constants.KEY_NAME);
                user.email = queryDocumentSnapshot.getString(Constants.KEY_EMAIL);
                user.image = queryDocumentSnapshot.getString(Constants.KEY_IMAGE);
                user.token = queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN);
                user.id = queryDocumentSnapshot.getId();
                users.add(user);
            }
            if (users.size() > 0) {
                UsersGCAdapter usersGCAdapter = new UsersGCAdapter(users, GroupChatActivity.this);
                binding.listFriend.setAdapter(usersGCAdapter);
                binding.listFriend.setVisibility(View.VISIBLE);
            } else {
                showError();
            }
        } else {
            showError();
        }
    });
}
Also used : UsersGCAdapter(com.example.clown.adapter.UsersGCAdapter) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.clown.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot)

Example 9 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project Skool by NhatTruongK15.

the class UsersActivity method getUsers.

private void getUsers() {
    loading(true);
    FirebaseFirestore database = FirebaseFirestore.getInstance();
    database.collection(Constants.KEY_COLLECTION_USERS).get().addOnCompleteListener(task -> {
        loading(false);
        String currentUserId = preferenceManager.getString(Constants.KEY_DOCUMENT_REFERENCE_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.name = queryDocumentSnapshot.getString(Constants.KEY_NAME);
                user.email = queryDocumentSnapshot.getString(Constants.KEY_EMAIL);
                user.image = queryDocumentSnapshot.getString(Constants.KEY_IMAGE);
                user.token = queryDocumentSnapshot.getString(Constants.KEY_FCM_TOKEN);
                user.id = queryDocumentSnapshot.getId();
                users.add(user);
            }
            if (users.size() > 0) {
                UsersAdapter usersAdapter = new UsersAdapter(users, this);
                binding.userRecyclerView.setAdapter(usersAdapter);
                binding.userRecyclerView.setVisibility(View.VISIBLE);
            } else {
                showError();
            }
        } else {
            showError();
        }
    });
}
Also used : UsersAdapter(com.example.clown.adapter.UsersAdapter) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) User(com.example.clown.models.User) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 10 with QueryDocumentSnapshot

use of com.google.firebase.firestore.QueryDocumentSnapshot in project turtleparties by CMPUT301W22T21.

the class MapsActivity method addQRMarkers.

public void addQRMarkers(@NonNull GoogleMap googleMap) {
    mMap = googleMap;
    db.collection("QR codes").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot doc : task.getResult()) {
                    String qrname = doc.getId();
                    db.collection("QR codes").document(qrname).get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {

                        @Override
                        public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                            if (task.isSuccessful()) {
                                DocumentSnapshot doc = task.getResult();
                                Integer score = ((Number) doc.getData().get("score")).intValue();
                                GeoPoint qrGeoPoint = (GeoPoint) doc.getData().get("geolocation");
                                Double latval = 0.0;
                                Double longval = 0.0;
                                try {
                                    latval = qrGeoPoint.getLatitude();
                                    longval = qrGeoPoint.getLongitude();
                                } catch (Exception e) {
                                    Log.d(TAG, "EMPTY GEOPOINT");
                                }
                                Log.d(TAG, latval + "  " + longval + "  " + score);
                                LatLng thisMarker = new LatLng(latval, longval);
                                mMap.addMarker(new MarkerOptions().position(thisMarker).title(String.valueOf(score)));
                            }
                        }
                    });
                }
            } else {
                Log.d(TAG, "Error getting documents: ", task.getException());
            }
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) WriterException(com.google.zxing.WriterException) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) GeoPoint(com.google.firebase.firestore.GeoPoint) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) NonNull(androidx.annotation.NonNull) LatLng(com.google.android.gms.maps.model.LatLng)

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