use of com.example.first_responder_app.dataModels.AnnouncementsDataModel 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.example.first_responder_app.dataModels.AnnouncementsDataModel in project FirstResponse by mattpost1700.
the class FirestoreDatabase method addAnnouncement.
// TODO: Add group id
public void addAnnouncement(String title, String description, UsersDataModel user) {
setActiveUser(user);
AnnouncementsDataModel newAnnoun = new AnnouncementsDataModel(activeUserFireDepartmentId, user.getDocumentId(), activeUser.getDocumentId(), title, description);
db.collection(ANNOUNCEMENTS_COLLECTION_DIR).add(newAnnoun).addOnSuccessListener(documentReference -> Log.d("new announcement page", "new announcement has been successfully created in the DB")).addOnFailureListener(e -> Log.d("new announcement page", "failed to create new announcement"));
}
use of com.example.first_responder_app.dataModels.AnnouncementsDataModel in project FirstResponse by mattpost1700.
the class AnnouncementRecyclerViewAdapter method onBindViewHolder.
// binds the data to the TextView in each row
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
AnnouncementsDataModel announ = mData.get(position);
holder.title.setText(announ.getTitle());
holder.des.setText(announ.getDescription());
String dateString = new SimpleDateFormat("MM/dd h:mm aa", Locale.getDefault()).format(announ.getCreated_at().toDate());
holder.annoucementTime.setText(dateString);
}
Aggregations