use of com.example.first_responder_app.recyclerViews.ReportGroupRecyclerViewAdapter 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();
}
Aggregations