use of com.example.first_responder_app.databinding.FragmentHomeBinding in project FirstResponse by mattpost1700.
the class HomeFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
if (drawerLocker != null) {
drawerLocker.setDrawerLocked(false);
}
FragmentHomeBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
bindingView = binding.getRoot();
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
// switch to Home fragment upon clicking it
// also if you have any other code relates to onCreateView just add it from here
activeUser = AppUtil.getActiveUser(getActivity());
if (activeUser == null) {
getActivity().getFragmentManager().popBackStack();
Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
}
// Setup click listeners for the view all incidents and view all responders buttons
binding.viewAllIncidents.setOnClickListener(view -> {
NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentGroupFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
binding.viewAllResponders.setOnClickListener(view -> {
NavDirections action = HomeFragmentDirections.actionHomeFragmentToRespondingFragment();
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();
});
binding.sortRespondersButton.setOnClickListener(view -> {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.setOnMenuItemClickListener(this);
popupMenu.inflate(R.menu.user_popup_menu);
popupMenu.show();
});
final SwipeRefreshLayout pullToRefresh = bindingView.findViewById(R.id.homeSwipeRefreshLayout);
pullToRefresh.setOnRefreshListener(() -> {
// your code
refreshData();
pullToRefresh.setRefreshing(false);
});
listOfIncidentDataModel = new ArrayList<>();
respondersList = new ArrayList<>();
listOfRanks = new ArrayList<>();
// automatically subscribes everyone who logs in to get notifications for these topics
FirebaseMessaging.getInstance().subscribeToTopic("events").addOnCompleteListener(new OnCompleteListener<>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
FirebaseMessaging.getInstance().subscribeToTopic("announcements").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
FirebaseMessaging.getInstance().subscribeToTopic("incidents").addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
}
});
saveRanksCollection();
RespondersRecyclerViewAdapter.ResponderClickListener responderClickListener = (view, position) -> {
UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
userViewModel.setUserDataModel(respondersList.get(position));
NavDirections action = HomeFragmentDirections.actionHomeFragmentToUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
IncidentRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
IncidentDataModel incident = listOfIncidentDataModel.get(position);
IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
incidentViewModel.setIncidentDataModel(incident);
NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
// RecyclerViews
RecyclerView incidentRecyclerView = bindingView.findViewById(R.id.incidents_recycler_view);
incidentRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
incidentRecyclerViewAdapter = new IncidentRecyclerViewAdapter(bindingView.getContext(), listOfIncidentDataModel);
incidentRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
incidentRecyclerView.setAdapter(incidentRecyclerViewAdapter);
RecyclerView respondersRecyclerView = bindingView.findViewById(R.id.responders_recycler_view);
respondersRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
respondersRecyclerViewAdapter = new RespondersRecyclerViewAdapter(bindingView.getContext(), respondersList, listOfIncidentDataModel);
respondersRecyclerViewAdapter.setResponderClickListener(responderClickListener);
respondersRecyclerView.setAdapter(respondersRecyclerViewAdapter);
// Start event listeners (live data)
addIncidentEventListener();
addResponderEventListener();
return bindingView;
}
Aggregations