content: package com.mlchatbot.ui;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  import com.mlchatbot.R;
  import java.util.List;
  
  public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.MessageViewHolder> {
      private static final int VIEW_TYPE_USER = 1;
      private static final int VIEW_TYPE_BOT = 2;
      
      private final List<MessageItem> messages;
  
      public ChatAdapter(List<MessageItem> messages) {
          this.messages = messages;
      }
  
      @NonNull
      @Override
      public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          int layoutResource = (viewType == VIEW_TYPE_USER) 
              ? R.layout.item_message_user 
              : R.layout.item_message_bot;
              
          View view = LayoutInflater.from(parent.getContext())
              .inflate(layoutResource, parent, false);
          return new MessageViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull MessageViewHolder holder, int position) {
          MessageItem message = messages.get(position);
          holder.messageText.setText(message.getMessage());
      }
  
      @Override
      public int getItemCount() {
          return messages.size();
      }
  
      @Override
      public int getItemViewType(int position) {
          MessageItem message = messages.get(position);
          return message.isUser() ? VIEW_TYPE_USER : VIEW_TYPE_BOT;
      }
  
      static class MessageViewHolder extends RecyclerView.ViewHolder {
          TextView messageText;
  
          MessageViewHolder(@NonNull View itemView) {
              super(itemView);
              messageText = itemView.findViewById(R.id.message_text);
          }
      }
  }
  