Search in sources :

Example 1 with EventGroupRecyclerViewAdapter

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

the class EventGroupFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    // binding fragment with nav_map by using navHostFragment, throw this block of code in there and that allows you to switch to other fragments
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_event_group, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    NavController navController = navHostFragment.getNavController();
    activeUser = AppUtil.getActiveUser(getActivity());
    if (activeUser == null) {
        getActivity().getFragmentManager().popBackStack();
        Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
    }
    listOfEvents = new ArrayList<>();
    populateEventList();
    EventGroupRecyclerViewAdapter.ItemClickListener eventClickListener = ((view, position, data) -> {
        // passing data to event
        mViewModel = new ViewModelProvider(requireActivity()).get(EventViewModel.class);
        mViewModel.setEventDetail(data);
        NavDirections action = EventGroupFragmentDirections.actionEventGroupFragmentToEventFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    RecyclerView eventGroupRecyclerView = binding.eventgroupRecycler;
    eventGroupRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    eventGroupRecyclerViewAdapter = new EventGroupRecyclerViewAdapter(getContext(), listOfEvents);
    eventGroupRecyclerViewAdapter.setClickListener(eventClickListener);
    eventGroupRecyclerView.setAdapter(eventGroupRecyclerViewAdapter);
    final SwipeRefreshLayout pullToRefresh = binding.eventSwipeRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        populateEventList();
        pullToRefresh.setRefreshing(false);
    });
    binding.newEventButton.setOnClickListener(v -> {
        NavDirections action = EventGroupFragmentDirections.actionEventGroupFragmentToNewEventFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    return binding.getRoot();
}
Also used : EventViewModel(com.example.first_responder_app.viewModels.EventViewModel) NavController(androidx.navigation.NavController) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) EventGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.EventGroupRecyclerViewAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavController (androidx.navigation.NavController)1 NavDirections (androidx.navigation.NavDirections)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 EventGroupRecyclerViewAdapter (com.example.first_responder_app.recyclerViews.EventGroupRecyclerViewAdapter)1 EventViewModel (com.example.first_responder_app.viewModels.EventViewModel)1