use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class HomeFragment method populateResponders.
public void populateResponders() {
db.collection("users").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereGreaterThanOrEqualTo(FirestoreDatabase.FIELD_RESPONDING_TIME, AppUtil.earliestTime(requireContext())).get().addOnCompleteListener(userTask -> {
Log.d(TAG, "READ DATABASE - HOME FRAGMENT (populateResponders)");
if (userTask.isSuccessful()) {
ArrayList<UsersDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : userTask.getResult()) {
UsersDataModel user = userDoc.toObject(UsersDataModel.class);
List<String> responses = user.getResponses();
if (responses != null && responses.size() > 0 && isActive(responses.get(responses.size() - 1)))
temp.add(user);
}
respondersList.clear();
respondersList.addAll(temp);
respondersRecyclerViewAdapter.notifyDataSetChanged();
// TODO: Should refresh
Log.d("TAG", "populateResponders: ");
}
});
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class IncidentFragment method initializeIncident.
/**
* Setup the incident data and display it
*
* @param incident The incident to be displayed
*/
public void initializeIncident(IncidentDataModel incident) {
setTextViews(incident);
Map<String, String> status = incident.getStatus();
// Get active user id
ActiveUser activeUser = (ActiveUser) getActivity();
if (activeUser != null) {
UsersDataModel user = activeUser.getActive();
if (user != null)
active_id = user.getDocumentId();
}
// Highlight active button
if (status != null && status.containsKey(active_id)) {
setActiveButton(status.get(active_id));
}
setRespondingButtonClickListener();
// Get the Address object of the incident
incidentAddress = addrToCoords(incident.getLocation());
setupLocationListener();
AtomicInteger prevLength = new AtomicInteger();
if (listenerRegistration == null) {
// Ensure that the incident data is updated if database is updated
docRef = FirestoreDatabase.getInstance().getDb().collection("incident").document(incident.getDocumentId());
listenerRegistration = docRef.addSnapshotListener((snapshot, e) -> {
Log.d(TAG, "READ DATABASE - INCIDENT FRAGMENT");
if (e != null) {
System.err.println("Listen failed: " + e);
return;
}
if (snapshot != null && snapshot.exists()) {
incidentDataModel = snapshot.toObject(IncidentDataModel.class);
if (incidentDataModel != null) {
setTextViews(incidentDataModel);
Map<String, String> statuses = incidentDataModel.getStatus();
if (statuses != null) {
String status1 = statuses.get(active_id);
setActiveButton(status1);
}
// Get the Address object of the incident
incidentAddress = addrToCoords(incidentDataModel.getLocation());
int currentLength = incidentDataModel.getResponding().size();
if (prevLength.get() != currentLength) {
prevLength.set(currentLength);
responderList.clear();
populateRespondersListFromDB();
}
}
} else {
System.out.print("Current data: null");
}
});
}
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class IncidentFragment method populateResponders.
public void populateResponders(int startIdx, int endIdx) {
FirestoreDatabase.getInstance().getDb().collection("users").whereIn(FieldPath.documentId(), incidentDataModel.getResponding().subList(startIdx, endIdx)).get().addOnCompleteListener(responderTask -> {
Log.d(TAG, "READ DATABASE - EVENT FRAGMENT");
if (responderTask.isSuccessful()) {
List<UsersDataModel> tempList = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : responderTask.getResult()) {
UsersDataModel userData = userDoc.toObject(UsersDataModel.class);
tempList.add(userData);
}
responderList.addAll(tempList);
responderArr = new CharSequence[responderList.size()];
for (int i = 0; i < responderList.size(); i++) {
responderArr[i] = responderList.get(i).getFull_name();
}
} else {
Log.w(TAG, "populateResponderList: Responder data failed to query", responderTask.getException());
}
});
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class CreateUserFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
if (drawerLocker != null) {
drawerLocker.setDrawerLocked(true);
}
binding = DataBindingUtil.inflate(inflater, R.layout.create_user_fragment, container, false);
mViewModel = new ViewModelProvider(requireActivity()).get(CreateUserViewModel.class);
binding.createUserFireDepartmentIdEditText.setText(mViewModel.getFireDepartmentId());
binding.createUserCreateButton.setOnClickListener(v -> {
if (validInput()) {
FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.FIRE_DEPARTMENT_COLLECTION_DIR).document(binding.createUserFireDepartmentIdEditText.getText().toString()).get().addOnSuccessListener(documentSnapshot -> {
if (documentSnapshot.toObject(UsersDataModel.class) != null) {
UsersDataModel newUser = new UsersDataModel();
fillUser(newUser);
FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.USERS_COLLECTION_DIR).add(newUser).addOnSuccessListener(documentReference -> {
// Success, login
if (FirestoreDatabase.getInstance().setActiveUser(newUser)) {
newUser.setDocumentId(documentReference.getId());
ActiveUser activeUser = ((ActiveUser) getActivity());
activeUser.setActive(newUser);
NavDirections action = CreateUserFragmentDirections.actionCreateUserFragmentToHomeFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
} else {
Toast.makeText(getContext(), "User does not have a department", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(e -> Toast.makeText(getContext(), "Failed to upload user. Network error", Toast.LENGTH_SHORT).show());
} else {
Toast.makeText(getContext(), "Fire department does not exist", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(e -> Toast.makeText(getContext(), "Cannot check for fire department. Network error", Toast.LENGTH_SHORT).show());
} else {
Toast.makeText(getContext(), "You must fill all of the text fields", Toast.LENGTH_SHORT).show();
}
});
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class NewChatFragment method populateUserList.
private void populateUserList() {
db.collection("users").get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot doc : task.getResult()) {
UsersDataModel u = new UsersDataModel(doc.getId(), (String) doc.get("first_name"), (String) doc.get("last_name"));
listOfUsers.add(u);
}
UsersDataModel currentU = new UsersDataModel(user.getDocumentId(), user.getFirst_name(), user.getLast_name());
listOfUsers.add(currentU);
} else {
Log.d(TAG, "db get failed in new chat page " + task.getException());
}
});
}
Aggregations