use of com.example.first_responder_app.recyclerViews.ChatGroupRecyclerViewAdapter in project FirstResponse by mattpost1700.
the class ChatGroupFragment 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
ChatGroupFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.chat_group_fragment, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
firestoreDatabase = new FirestoreDatabase();
db = firestoreDatabase.getDb();
activeUser = (ActiveUser) getActivity();
if (activeUser != null) {
user = activeUser.getActive();
}
listOfChats = new ArrayList<>();
populateChatList();
ChatGroupRecyclerViewAdapter.ItemClickListener chatClickListener = ((view, position, data) -> {
// passing data to chat
mViewModel = new ViewModelProvider(requireActivity()).get(ChatViewModel.class);
mViewModel.setChatDetail(data);
List<Message> temp = new ArrayList<>();
mViewModel.setListOfMessages(temp);
NavDirections action = ChatGroupFragmentDirections.actionChatGroupFragmentToChatFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
RecyclerView chatGroupRecyclerView = binding.chatGroupRecyclerView;
chatGroupRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
chatGroupRecyclerViewAdapter = new ChatGroupRecyclerViewAdapter(getContext(), listOfChats);
chatGroupRecyclerViewAdapter.setClickListener(chatClickListener);
chatGroupRecyclerView.setAdapter(chatGroupRecyclerViewAdapter);
binding.chatTextView.setOnClickListener(v -> {
NavDirections action = ChatGroupFragmentDirections.actionChatGroupFragmentToChatFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
binding.addChatTextView.setOnClickListener(v -> {
NavDirections action = ChatGroupFragmentDirections.actionChatGroupFragmentToNewChatFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
return binding.getRoot();
}
Aggregations