use of com.example.first_responder_app.dataModels.ReportDataModel in project FirstResponse by mattpost1700.
the class ReportFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_report, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
View bindingView = binding.getRoot();
activeUser = AppUtil.getActiveUser(getActivity());
if (activeUser == null) {
getActivity().getFragmentManager().popBackStack();
Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
}
ReportViewModel mViewModel = new ViewModelProvider(requireActivity()).get(ReportViewModel.class);
incident = mViewModel.getIncidentDataModel();
setText();
binding.floatingActionButton.setOnClickListener(view -> {
// Send to db
// String fire_department_id, String incident_id, String user_created_id, String address, String units, String box_number, String incident_type, String narrative) {
ReportDataModel report = null;
try {
report = new ReportDataModel(activeUser.getFire_department_id(), incident.getDocumentId(), activeUser.getDocumentId(), binding.addressTextView.getText().toString(), binding.unitsTextView.getText().toString(), binding.boxNumberTextView.getText().toString(), binding.incidentTypeTextView.getText().toString(), binding.reportOfficerText.getText().toString());
} catch (NullPointerException nullPointerException) {
report = null;
Toast.makeText(getActivity(), "You must fill out the whole form", Toast.LENGTH_SHORT).show();
}
if (report != null) {
FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.REPORTS_COLLECTION_DIR).add(report).addOnSuccessListener(documentReference -> {
Log.d(TAG, "onCreateView: added " + documentReference);
Toast.makeText(getActivity(), "Report saved!", Toast.LENGTH_SHORT).show();
NavDirections action = ReportFragmentDirections.actionReportFragmentToIncidentFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
}).addOnFailureListener(e -> Log.e(TAG, "onCreateView: Failed to upload document!", e));
}
});
return bindingView;
}
use of com.example.first_responder_app.dataModels.ReportDataModel 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.example.first_responder_app.dataModels.ReportDataModel in project FirstResponse by mattpost1700.
the class ReportGroupFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = DataBindingUtil.inflate(inflater, R.layout.report_group_fragment, container, false);
activeUser = AppUtil.getActiveUser(getActivity());
reports = new ArrayList<>();
ReportGroupRecyclerViewAdapter.ReportClickListener reportClickListener = (view, position) -> {
// TODO: setup click listener to edit report
EditReportViewModel editReportViewModel = new ViewModelProvider(requireActivity()).get(EditReportViewModel.class);
editReportViewModel.setReport(reports.get(position));
NavDirections action = ReportGroupFragmentDirections.actionReportGroupFragmentToEditReport();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
ReportGroupRecyclerViewAdapter.ReportLongClickListener reportLongClickListener = (view, position) -> {
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()).setTitle("Delete Report").setMessage("Are you sure you want to delete this report?").setPositiveButton("Yes", (dialogInterface, i) -> {
ReportDataModel report = reports.get(position);
db.collection("reports").document(report.getDocumentId()).delete();
reports.remove(position);
checkReportsEmpty();
reportGroupRecyclerViewAdapter.notifyDataSetChanged();
}).setNegativeButton("No", (dialogInterface, i) -> {
});
dialog.show();
};
RecyclerView reportGroupRecyclerView = binding.reportGroupRecycler;
reportGroupRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
reportGroupRecyclerViewAdapter = new ReportGroupRecyclerViewAdapter(getContext(), reports);
reportGroupRecyclerViewAdapter.setReportClickListener(reportClickListener);
reportGroupRecyclerViewAdapter.setReportLongClickListener(reportLongClickListener);
reportGroupRecyclerView.setAdapter(reportGroupRecyclerViewAdapter);
populateReports();
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.ReportDataModel in project FirstResponse by mattpost1700.
the class ReportGroupRecyclerViewAdapter method onBindViewHolder.
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull ReportGroupRecyclerViewAdapter.ViewHolder holder, int position) {
ReportDataModel report = reportList.get(position);
Date date = report.getCreated_at().toDate();
String dateString = new SimpleDateFormat("MM/dd/yy", Locale.getDefault()).format(date);
holder.reportAddressTextView.setText(report.getAddress());
holder.reportDateTextView.setText(dateString);
}
Aggregations