Search in sources :

Example 1 with IncidentGroupRecyclerViewAdapter

use of com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter in project FirstResponse by mattpost1700.

the class IncidentGroupFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_incident_group, container, false);
    listOfIncidentDataModel = new ArrayList<>();
    activeUser = AppUtil.getActiveUser(getActivity());
    if (activeUser == null) {
        getActivity().getFragmentManager().popBackStack();
        Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
    }
    final SwipeRefreshLayout pullToRefresh = binding.incidentGroupSwipeRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        refreshData();
        pullToRefresh.setRefreshing(false);
    });
    IncidentGroupRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
        IncidentDataModel incident = listOfIncidentDataModel.get(position);
        IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
        incidentViewModel.setIncidentDataModel(incident);
        NavDirections action = IncidentGroupFragmentDirections.actionIncidentGroupFragmentToIncidentFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    };
    binding.sortIncidentsButton.setOnClickListener(view -> {
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.inflate(R.menu.incident_popup_menu);
        popupMenu.show();
    });
    // Recycler view
    RecyclerView incidentRecyclerView = binding.incidentsGroupRecyclerView;
    incidentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    incidentGroupRecyclerViewAdapter = new IncidentGroupRecyclerViewAdapter(getContext(), listOfIncidentDataModel);
    incidentGroupRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
    incidentRecyclerView.setAdapter(incidentGroupRecyclerViewAdapter);
    addIncidentEventListener();
    // inflater.inflate(R.layout.fragment_incident_group, container, false);
    return binding.getRoot();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Query(com.google.firebase.firestore.Query) IncidentGroupViewModel(com.example.first_responder_app.viewModels.IncidentGroupViewModel) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) PopupMenu(android.widget.PopupMenu) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) AppUtil(com.example.first_responder_app.AppUtil) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) Nullable(androidx.annotation.Nullable) FragmentIncidentGroupBinding(com.example.first_responder_app.databinding.FragmentIncidentGroupBinding) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) IncidentGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) RecyclerView(androidx.recyclerview.widget.RecyclerView) IncidentGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) PopupMenu(android.widget.PopupMenu)

Aggregations

TAG (android.content.ContentValues.TAG)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 PopupMenu (android.widget.PopupMenu)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)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 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 AppUtil (com.example.first_responder_app.AppUtil)1