Search in sources :

Example 1 with AnnouncementRecyclerViewAdapter

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

the class AnnouncementFragment 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_announcement, 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();
    }
    listOfAnnouncements = new ArrayList<>();
    populateAnnouncmentList();
    RecyclerView announcementRecyclerView = binding.rvAnnoun;
    announcementRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    announcementAdapter = new AnnouncementRecyclerViewAdapter(getContext(), listOfAnnouncements);
    announcementRecyclerView.setAdapter(announcementAdapter);
    final SwipeRefreshLayout pullToRefresh = binding.announcementSwipeRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        populateAnnouncmentList();
        pullToRefresh.setRefreshing(false);
    });
    binding.newAnnouncementButton.setOnClickListener(v -> {
        NavDirections action = AnnouncementFragmentDirections.actionAnnouncementFragmentToNewAnnouncementFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    return binding.getRoot();
}
Also used : AnnouncementRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.AnnouncementRecyclerViewAdapter) NavController(androidx.navigation.NavController) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NavHostFragment(androidx.navigation.fragment.NavHostFragment) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) NavDirections(androidx.navigation.NavDirections)

Aggregations

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 AnnouncementRecyclerViewAdapter (com.example.first_responder_app.recyclerViews.AnnouncementRecyclerViewAdapter)1