Search in sources :

Example 1 with ChatGroupFragmentBinding

use of com.example.first_responder_app.databinding.ChatGroupFragmentBinding 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();
}
Also used : Message(com.example.first_responder_app.messaging.Message) ArrayList(java.util.ArrayList) NavController(androidx.navigation.NavController) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NavDirections(androidx.navigation.NavDirections) ChatGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.ChatGroupRecyclerViewAdapter) ChatViewModel(com.example.first_responder_app.viewModels.ChatViewModel) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavHostFragment(androidx.navigation.fragment.NavHostFragment) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) ChatGroupFragmentBinding(com.example.first_responder_app.databinding.ChatGroupFragmentBinding) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 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 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)1 ChatGroupFragmentBinding (com.example.first_responder_app.databinding.ChatGroupFragmentBinding)1 Message (com.example.first_responder_app.messaging.Message)1 ChatGroupRecyclerViewAdapter (com.example.first_responder_app.recyclerViews.ChatGroupRecyclerViewAdapter)1 ChatViewModel (com.example.first_responder_app.viewModels.ChatViewModel)1 ArrayList (java.util.ArrayList)1