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;
}
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
}
});
}
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();
}
});
}
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();
}
});
}
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());
}
}
});
}
Aggregations