use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class IncidentRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull IncidentRecyclerViewAdapter.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());
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class RespondersGroupRecyclerViewAdapter method setResponseLocation.
/**
* Set the responding location field on the card
*
* @param holder The ViewHolder object
* @param user The user who is responding
*/
public void setResponseLocation(ViewHolder holder, UsersDataModel user) {
StringBuilder responding = new StringBuilder();
Log.d(TAG, "setResponseLocation: ");
for (int i = 0; i < incidentList.size(); i++) {
IncidentDataModel incident = incidentList.get(i);
Map<String, String> status = incident.getStatus();
List<String> responses = user.getResponses();
if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Station")) {
holder.responderRankTextView.setText("Station");
} else if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Unavailable")) {
holder.responderRankTextView.setText("Unavailable");
} else {
holder.responderRankTextView.setText(incident.getLocation());
}
return;
}
}
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class RespondersRecyclerViewAdapter method setEta.
public void setEta(ViewHolder holder, UsersDataModel user) {
for (int i = 0; i < incidentList.size(); i++) {
IncidentDataModel incident = incidentList.get(i);
Map<String, String> etas = incident.getEta();
List<String> responses = user.getResponses();
if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
if (etas != null && etas.containsKey(user.getDocumentId())) {
String eta = "ETA: " + etas.get(user.getDocumentId());
holder.responderEtaTextView.setText(eta);
return;
}
}
}
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class RespondersRecyclerViewAdapter method setResponseLocation.
/**
* Set the responding location field on the card
*
* @param holder The ViewHolder object
* @param user The user who is responding
*/
public void setResponseLocation(ViewHolder holder, UsersDataModel user) {
StringBuilder responding = new StringBuilder();
Log.d(TAG, "setResponseLocation: ");
for (int i = 0; i < incidentList.size(); i++) {
IncidentDataModel incident = incidentList.get(i);
Map<String, String> status = incident.getStatus();
List<String> responses = user.getResponses();
if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Station")) {
holder.responderRankTextView.setText("Station");
} else if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Unavailable")) {
holder.responderRankTextView.setText("Unavailable");
} else {
holder.responderRankTextView.setText(incident.getLocation());
}
return;
}
}
}
use of com.example.first_responder_app.dataModels.IncidentDataModel in project FirstResponse by mattpost1700.
the class HomeFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
if (drawerLocker != null) {
drawerLocker.setDrawerLocked(false);
}
FragmentHomeBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
bindingView = binding.getRoot();
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
// switch to Home fragment upon clicking it
// also if you have any other code relates to onCreateView just add it from here
activeUser = AppUtil.getActiveUser(getActivity());
if (activeUser == null) {
getActivity().getFragmentManager().popBackStack();
Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
}
// Setup click listeners for the view all incidents and view all responders buttons
binding.viewAllIncidents.setOnClickListener(view -> {
NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentGroupFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
binding.viewAllResponders.setOnClickListener(view -> {
NavDirections action = HomeFragmentDirections.actionHomeFragmentToRespondingFragment();
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();
});
binding.sortRespondersButton.setOnClickListener(view -> {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.setOnMenuItemClickListener(this);
popupMenu.inflate(R.menu.user_popup_menu);
popupMenu.show();
});
final SwipeRefreshLayout pullToRefresh = bindingView.findViewById(R.id.homeSwipeRefreshLayout);
pullToRefresh.setOnRefreshListener(() -> {
// your code
refreshData();
pullToRefresh.setRefreshing(false);
});
listOfIncidentDataModel = new ArrayList<>();
respondersList = new ArrayList<>();
listOfRanks = new ArrayList<>();
// automatically subscribes everyone who logs in to get notifications for these topics
FirebaseMessaging.getInstance().subscribeToTopic("events").addOnCompleteListener(new OnCompleteListener<>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
FirebaseMessaging.getInstance().subscribeToTopic("announcements").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
FirebaseMessaging.getInstance().subscribeToTopic("incidents").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
saveRanksCollection();
RespondersRecyclerViewAdapter.ResponderClickListener responderClickListener = (view, position) -> {
UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
userViewModel.setUserDataModel(respondersList.get(position));
NavDirections action = HomeFragmentDirections.actionHomeFragmentToUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
IncidentRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
IncidentDataModel incident = listOfIncidentDataModel.get(position);
IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
incidentViewModel.setIncidentDataModel(incident);
NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
// RecyclerViews
RecyclerView incidentRecyclerView = bindingView.findViewById(R.id.incidents_recycler_view);
incidentRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
incidentRecyclerViewAdapter = new IncidentRecyclerViewAdapter(bindingView.getContext(), listOfIncidentDataModel);
incidentRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
incidentRecyclerView.setAdapter(incidentRecyclerViewAdapter);
RecyclerView respondersRecyclerView = bindingView.findViewById(R.id.responders_recycler_view);
respondersRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
respondersRecyclerViewAdapter = new RespondersRecyclerViewAdapter(bindingView.getContext(), respondersList, listOfIncidentDataModel);
respondersRecyclerViewAdapter.setResponderClickListener(responderClickListener);
respondersRecyclerView.setAdapter(respondersRecyclerViewAdapter);
// Start event listeners (live data)
addIncidentEventListener();
addResponderEventListener();
return bindingView;
}
Aggregations