use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class ReportGroupFragment method populateReports.
private void populateReports() {
db.collection("reports").whereEqualTo("user_created_id", activeUser.getDocumentId()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ArrayList<ReportDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot reportDoc : task.getResult()) {
ReportDataModel reportDataModel = reportDoc.toObject(ReportDataModel.class);
temp.add(reportDataModel);
}
reports.clear();
reports.addAll(temp);
checkReportsEmpty();
reportGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.w(TAG, "onCreateView: get failed in HomeFragment with", task.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class AnnouncementFragment method populateAnnouncmentList.
private void populateAnnouncmentList() {
Task getAnnoucementsForGroups = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereIn("intended_group_id", activeUser.getGroup_ids()).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
Task getAnnouncementsForAll = db.collection("announcements").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereEqualTo("intended_group_id", null).orderBy(FirestoreDatabase.FIELD_CREATED_AT, Query.Direction.DESCENDING).get();
Tasks.whenAllSuccess(getAnnoucementsForGroups, getAnnouncementsForAll).addOnSuccessListener(objects -> {
ArrayList<AnnouncementsDataModel> temp = new ArrayList<>();
for (Object fakeQuerySnapshot : objects) {
QuerySnapshot querySnapshot = ((QuerySnapshot) fakeQuerySnapshot);
for (QueryDocumentSnapshot announcementDoc : querySnapshot) {
AnnouncementsDataModel announcementDataModel = announcementDoc.toObject(AnnouncementsDataModel.class);
temp.add(announcementDataModel);
}
}
listOfAnnouncements.clear();
listOfAnnouncements.addAll(temp);
checkAnnouncementEmpty();
announcementAdapter.notifyDataSetChanged();
}).addOnFailureListener(e -> Log.e(TAG, "populateAnnouncmentList: db get failed in announcement page", e));
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class ChatGroupFragment method populateChatList.
private void populateChatList() {
db.collection("chat").get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ArrayList<Chat> temp = new ArrayList<>();
for (QueryDocumentSnapshot doc : task.getResult()) {
ArrayList<String> members = (ArrayList<String>) doc.get("members");
if (user != null) {
String memberName = user.getFirst_name() + " " + user.getLast_name() + "/" + user.getDocumentId();
if (members.contains(memberName)) {
Timestamp t = (Timestamp) doc.get("most_recent_message_time");
Chat chat = new Chat(doc.getId(), (String) doc.get("most_recent_message"), members, (String) doc.get("chat_name"), t);
temp.add(chat);
}
}
}
listOfChats.clear();
listOfChats.addAll(temp);
Collections.sort(listOfChats);
Collections.reverse(listOfChats);
chatGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.d(TAG, "db get failed in chat group page " + task.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project host-me by host-me-app.
the class EmailValidator method getEmailFromDataBase.
/**
* Fetch emails from the database
*
* @return Emails from accounts in the database
* @throws ExecutionException
* @throws InterruptedException
* @throws TimeoutException
*/
private static List<String> getEmailFromDataBase() throws ExecutionException, InterruptedException, TimeoutException {
List<String> emails = new ArrayList<>();
Task<QuerySnapshot> task = DB.collection("users").get();
Tasks.await(task, 5000, TimeUnit.MILLISECONDS);
for (QueryDocumentSnapshot document : task.getResult()) {
emails.add(document.getString("email"));
}
Log.i("DB", emails.toString());
return emails;
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirebaseUI-Android by firebase.
the class FirestoreArray method onDocumentAdded.
private void onDocumentAdded(DocumentChange change) {
QueryDocumentSnapshot snapshot = change.getDocument();
mSnapshots.add(change.getNewIndex(), snapshot);
notifyOnChildChanged(ChangeEventType.ADDED, snapshot, change.getNewIndex(), -1);
}
Aggregations