Search in sources :

Example 1 with ReportGroupRecyclerViewAdapter

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();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) ReportGroupFragmentBinding(com.example.first_responder_app.databinding.ReportGroupFragmentBinding) ArrayList(java.util.ArrayList) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) DialogInterface(android.content.DialogInterface) ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) EditReportViewModel(com.example.first_responder_app.viewModels.EditReportViewModel) AppUtil(com.example.first_responder_app.AppUtil) ReportGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.ReportGroupRecyclerViewAdapter) ReportGroupViewModel(com.example.first_responder_app.viewModels.ReportGroupViewModel) ViewGroup(android.view.ViewGroup) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) AlertDialog(android.app.AlertDialog) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) Nullable(androidx.annotation.Nullable) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) IncidentGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter) DialogFragment(androidx.fragment.app.DialogFragment) AlertDialog(android.app.AlertDialog) ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ReportGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.ReportGroupRecyclerViewAdapter) NavDirections(androidx.navigation.NavDirections) EditReportViewModel(com.example.first_responder_app.viewModels.EditReportViewModel) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

AlertDialog (android.app.AlertDialog)1 TAG (android.content.ContentValues.TAG)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 DialogFragment (androidx.fragment.app.DialogFragment)1 Fragment (androidx.fragment.app.Fragment)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavDirections (androidx.navigation.NavDirections)1 Navigation (androidx.navigation.Navigation)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AppUtil (com.example.first_responder_app.AppUtil)1