Search in sources :

Example 1 with RespondersGroupRecyclerViewAdapter

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

the class RespondingFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_responding, container, false);
    listOfRespondingDataModel = new ArrayList<>();
    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.respondingSwipeRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        refreshData();
        pullToRefresh.setRefreshing(false);
    });
    // onclick
    RespondersGroupRecyclerViewAdapter.ResponderClickListener responderClickListener = (view, position) -> {
        UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
        userViewModel.setUserDataModel(listOfRespondingDataModel.get(position));
        NavDirections action = RespondingFragmentDirections.actionRespondingFragmentToUserFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    };
    binding.sortRespondersButton.setOnClickListener(view -> {
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.inflate(R.menu.user_popup_menu);
        popupMenu.show();
    });
    // Recycler view
    RecyclerView respondingRecyclerView = binding.respondingRecyclerView;
    respondingRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    respondingRecyclerViewAdapter = new RespondersGroupRecyclerViewAdapter(getContext(), listOfRespondingDataModel, listOfIncidentDataModel);
    respondingRecyclerViewAdapter.setResponderClickListener(responderClickListener);
    respondingRecyclerView.setAdapter(respondingRecyclerViewAdapter);
    addResponderEventListener();
    addIncidentEventListener();
    return binding.getRoot();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) 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) Timestamp(com.google.firebase.Timestamp) 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) FragmentRespondingBinding(com.example.first_responder_app.databinding.FragmentRespondingBinding) ViewGroup(android.view.ViewGroup) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) Nullable(androidx.annotation.Nullable) RespondingViewModel(com.example.first_responder_app.viewModels.RespondingViewModel) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RespondersGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.RespondersGroupRecyclerViewAdapter) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) RespondersGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.RespondersGroupRecyclerViewAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) 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