use of com.example.first_responder_app.recyclerViews.EventRecyclerViewAdapter in project FirstResponse by mattpost1700.
the class EventFragment method onCreateView.
@SuppressLint("SetTextI18n")
@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, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavController navController = navHostFragment.getNavController();
// initialize vars as well as fetching userID
participants = new ArrayList<>();
ActiveUser activeUser = (ActiveUser) getActivity();
UsersDataModel user = activeUser.getActive();
userID = user.getDocumentId();
// getting data from event group
mViewModel = new ViewModelProvider(requireActivity()).get(EventViewModel.class);
eventInfo = mViewModel.getEventDetail();
isParticipating = eventInfo.getParticipants().contains(user.getDocumentId());
EventRecyclerViewAdapter.ItemClickListener listener = (view, pos) -> {
UsersDataModel u = participants.get(pos);
UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
userViewModel.setUserDataModel(u);
NavDirections action = EventFragmentDirections.actionEventFragmentToUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
};
// recycler binding
RecyclerView eventRecyclerView = binding.eventEventRecycler;
eventRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
eventRecyclerViewAdapter = new EventRecyclerViewAdapter(getContext(), participants, isAnyParticipants);
eventRecyclerViewAdapter.setClickListener(listener);
eventRecyclerView.setAdapter(eventRecyclerViewAdapter);
updateUI(false);
final SwipeRefreshLayout pullToRefresh = binding.eventRefreshLayout;
pullToRefresh.setOnRefreshListener(() -> {
participants.clear();
updateUI(true);
pullToRefresh.setRefreshing(false);
});
addParticipatingEventListener();
binding.signUp.setOnClickListener(v -> {
if (binding.signUp.getText().equals("Withdraw")) {
eventInfo.getParticipants().remove(userID);
db.collection(FirestoreDatabase.EVENTS_COLLECTION_DIR).document(eventInfo.getDocumentId()).set(eventInfo).addOnSuccessListener(documentReference -> {
isParticipating = false;
binding.signUp.setText("Sign Up");
}).addOnFailureListener(e -> Log.w(TAG, "onCreateView: Could not update event UI", e));
} else {
eventInfo.getParticipants().add(userID);
db.collection(FirestoreDatabase.EVENTS_COLLECTION_DIR).document(eventInfo.getDocumentId()).set(eventInfo).addOnSuccessListener(documentReference -> {
isParticipating = true;
binding.signUp.setText("Withdraw");
}).addOnFailureListener(e -> Log.w(TAG, "onCreateView: Could not update event UI", e));
// sends the event that includes the following:
// title, location, description, duration
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
intent.putExtra(CalendarContract.Events.TITLE, eventInfo.getTitle());
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, eventInfo.getLocation());
intent.putExtra(CalendarContract.Events.DESCRIPTION, eventInfo.getDescription());
intent.putExtra(CalendarContract.Events.DURATION, eventInfo.getDuration_in_minutes());
if (intent.resolveActivity(requireContext().getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("EVENT INTENT: ", "Event setup Failed");
}
// // Calendar intent
// Calendar cal = Calendar.getInstance();
// Intent intent = new Intent(Intent.ACTION_EDIT);
// long startTime = eventInfo.getEvent_time().toDate().toInstant().toEpochMilli();
// intent.putExtra("beginTime", startTime);
// //intent.putExtra("allDay", true);
// intent.putExtra("endTime", startTime + AppUtil.numOfMinutesToMilliSeconds(eventInfo.getDuration_in_minutes()));
// intent.putExtra("title", "A Test Event from android app");
// startActivity(intent);
}
});
return binding.getRoot();
}
Aggregations