use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class HomeFragment method populateIncidents.
/**
* Displays the active incidents
*/
private void populateIncidents() {
db.collection("incident").whereArrayContains(FirestoreDatabase.FIELD_FIRE_DEPARTMENTS, activeUser.getFire_department_id()).whereEqualTo("incident_complete", false).get().addOnCompleteListener(incidentTask -> {
Log.d(TAG, "READ DATABASE - HOME FRAGMENT (populateIncidents)");
if (incidentTask.isSuccessful()) {
ArrayList<IncidentDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot incidentDoc : incidentTask.getResult()) {
IncidentDataModel incidentDataModel = incidentDoc.toObject(IncidentDataModel.class);
temp.add(incidentDataModel);
}
listOfIncidentDataModel.clear();
listOfIncidentDataModel.addAll(temp);
incidentRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.d(TAG, "get failed in HomeFragment with " + incidentTask.getException());
}
});
}
use of com.example.first_responder_app.dataModels.IncidentDataModel 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.IncidentDataModel in project FirstResponse by mattpost1700.
the class IncidentGroupFragment method refreshData.
private void refreshData() {
db.collection("incident").whereArrayContains(FirestoreDatabase.FIELD_FIRE_DEPARTMENTS, activeUser.getFire_department_id()).get().addOnCompleteListener(incidentTask -> {
Log.d(TAG, "READ DATABASE - INCIDENT GROUP FRAGMENT");
if (incidentTask.isSuccessful()) {
ArrayList<IncidentDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot incidentDoc : incidentTask.getResult()) {
IncidentDataModel incidentDataModel = incidentDoc.toObject(IncidentDataModel.class);
temp.add(incidentDataModel);
}
listOfIncidentDataModel.clear();
listOfIncidentDataModel.addAll(temp);
checkIncidentsEmpty();
incidentGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.w(TAG, "onCreateView: get failed in HomeFragment with", incidentTask.getException());
}
});
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class IncidentGroupFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_incident_group, container, false);
listOfIncidentDataModel = new ArrayList<>();
activeUser = AppUtil.getActiveUser(getActivity());
if (activeUser == null) {
getActivity().getFragmentManager().popBackStack();
Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
}
final SwipeRefreshLayout pullToRefresh = binding.incidentGroupSwipeRefreshLayout;
pullToRefresh.setOnRefreshListener(() -> {
refreshData();
pullToRefresh.setRefreshing(false);
});
IncidentGroupRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
IncidentDataModel incident = listOfIncidentDataModel.get(position);
IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
incidentViewModel.setIncidentDataModel(incident);
NavDirections action = IncidentGroupFragmentDirections.actionIncidentGroupFragmentToIncidentFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
binding.sortIncidentsButton.setOnClickListener(view -> {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.setOnMenuItemClickListener(this);
popupMenu.inflate(R.menu.incident_popup_menu);
popupMenu.show();
});
// Recycler view
RecyclerView incidentRecyclerView = binding.incidentsGroupRecyclerView;
incidentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
incidentGroupRecyclerViewAdapter = new IncidentGroupRecyclerViewAdapter(getContext(), listOfIncidentDataModel);
incidentGroupRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
incidentRecyclerView.setAdapter(incidentGroupRecyclerViewAdapter);
addIncidentEventListener();
// inflater.inflate(R.layout.fragment_incident_group, container, false);
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class IncidentGroupRecyclerViewAdapter method onBindViewHolder.
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull IncidentGroupRecyclerViewAdapter.ViewHolder holder, int position) {
IncidentDataModel incident = incidentList.get(position);
Date date = incident.getCreated_at().toDate();
String dateString = new SimpleDateFormat("h:mm aa", Locale.getDefault()).format(date);
holder.incidentAddressTextView.setText(incident.getLocation());
holder.incidentTimeTextView.setText(dateString);
holder.incidentTypeChip.setText(incident.getIncident_type());
}
Aggregations