Search in sources :

Example 1 with ReportDataModel

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;
}
Also used : ReportViewModel(com.example.first_responder_app.viewModels.ReportViewModel) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) Locale(java.util.Locale) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ReportViewModel(com.example.first_responder_app.viewModels.ReportViewModel) TAG(android.content.ContentValues.TAG) FragmentReportBinding(com.example.first_responder_app.databinding.FragmentReportBinding) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) 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) Timestamp(java.sql.Timestamp) AppUtil(com.example.first_responder_app.AppUtil) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) Nullable(androidx.annotation.Nullable) Navigation(androidx.navigation.Navigation) ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) NavHostFragment(androidx.navigation.fragment.NavHostFragment) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections)

Example 2 with ReportDataModel

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());
        }
    });
}
Also used : ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 3 with ReportDataModel

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();
}
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)

Example 4 with ReportDataModel

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);
}
Also used : ReportDataModel(com.example.first_responder_app.dataModels.ReportDataModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) SuppressLint(android.annotation.SuppressLint)

Aggregations

ReportDataModel (com.example.first_responder_app.dataModels.ReportDataModel)4 TAG (android.content.ContentValues.TAG)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 DataBindingUtil (androidx.databinding.DataBindingUtil)2 Fragment (androidx.fragment.app.Fragment)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2 NavDirections (androidx.navigation.NavDirections)2 Navigation (androidx.navigation.Navigation)2 AppUtil (com.example.first_responder_app.AppUtil)2 R (com.example.first_responder_app.R)2 IncidentDataModel (com.example.first_responder_app.dataModels.IncidentDataModel)2 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)2 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)2