Search in sources :

Example 1 with FragmentIncidentBinding

use of com.example.first_responder_app.databinding.FragmentIncidentBinding in project FirstResponse by mattpost1700.

the class IncidentFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    FragmentIncidentBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_incident, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    bindingView = binding.getRoot();
    context = getContext();
    Log.d(TAG, "onCreateView: " + bindingView.findViewById(R.id.incident_button_layout));
    Bundle mapViewBundle = null;
    if (savedInstanceState != null) {
        mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY);
    }
    mMapView = (MapView) binding.googleMapView;
    mMapView.onCreate(mapViewBundle);
    mMapView.getMapAsync(this);
    mViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
    incident = mViewModel.getIncidentDataModel();
    responderList = new ArrayList<>();
    Log.d(TAG, "onCreate: " + getActivity().findViewById(R.id.incident_button_layout));
    initializeIncident(incident);
    // TODO: Check if user has permissions to file report (If not hide FAB)
    binding.incidentFileReportButton.setOnClickListener(v -> {
        ReportViewModel userViewModel = new ViewModelProvider(requireActivity()).get(ReportViewModel.class);
        userViewModel.setIncidentDataModel(incidentDataModel);
        NavDirections action = IncidentFragmentDirections.actionIncidentFragmentToReportFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    // setup the dialog upon clicking the responder count icon, clicking on individual item will redirect to their profile page
    binding.incidentRespondingCount.setOnClickListener(v -> {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater layoutInflater = getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.dialog_title, null);
        builder.setCustomTitle(view).setItems(responderArr, (dialogInterface, i) -> {
            mUserViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
            mUserViewModel.setUserDataModel(responderList.get(i));
            NavDirections action = IncidentFragmentDirections.actionIncidentFragmentToUserFragment();
            Navigation.findNavController(binding.getRoot()).navigate(action);
        });
        builder.setNegativeButton("Cancel", (dialogInterface, i) -> {
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    });
    return binding.getRoot();
}
Also used : ReportViewModel(com.example.first_responder_app.viewModels.ReportViewModel) AlertDialog(android.app.AlertDialog) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) Bundle(android.os.Bundle) FragmentIncidentBinding(com.example.first_responder_app.databinding.FragmentIncidentBinding) View(android.view.View) MapView(com.google.android.gms.maps.MapView) TextView(android.widget.TextView) NavDirections(androidx.navigation.NavDirections) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) LayoutInflater(android.view.LayoutInflater) NavHostFragment(androidx.navigation.fragment.NavHostFragment) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

AlertDialog (android.app.AlertDialog)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 TextView (android.widget.TextView)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavDirections (androidx.navigation.NavDirections)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1 FragmentIncidentBinding (com.example.first_responder_app.databinding.FragmentIncidentBinding)1 IncidentViewModel (com.example.first_responder_app.viewModels.IncidentViewModel)1 ReportViewModel (com.example.first_responder_app.viewModels.ReportViewModel)1 UserViewModel (com.example.first_responder_app.viewModels.UserViewModel)1 MapView (com.google.android.gms.maps.MapView)1