Commit 0edd0de4 authored by Hansi rathnayaka's avatar Hansi rathnayaka

final version of chat feature

parent aeb5d7b0
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\wishwa\.android\avd\Pixel_2_API_25.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2021-10-12T20:49:47.662287500Z" />
</component>
</project>
\ No newline at end of file
package com.project.skidn_disease_app.Adapters;
import android.content.Context;
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.project.skidn_disease_app.R;
import com.project.skidn_disease_app.model.ChatModal;
import com.project.skidn_disease_app.model.MsgModal;
import java.util.ArrayList;
public class ChatRvAdpater extends RecyclerView.Adapter {
private ArrayList<ChatModal> chatMsgModals;
private Context context;
public ChatRvAdpater(ArrayList<ChatModal> chatMsgModals, Context context) {
this.chatMsgModals = chatMsgModals;
this.context = context;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
switch (viewType){
case 0:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.user_msg_rv_item,parent,false);
return new UserViewHolder(view);
case 1:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.bot_msg_rv_item,parent,false);
return new BotViewHolder(view);
}
return null;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ChatModal chatModal = chatMsgModals.get(position);
switch (chatModal.getSender()){
case "user":
((UserViewHolder)holder).userTv.setText(chatModal.getMessage());
break;
case "bot":
System.out.println(holder.getItemViewType());
BotViewHolder botViewHolder = ((BotViewHolder)holder);
botViewHolder.idTVBot.setText(chatModal.getMessage());
break;
}
}
@Override
public int getItemViewType(int position) {
switch (chatMsgModals.get(position).getSender()){
case "user":
return 0;
case "bot":
return 1;
default:
return -1;
}
}
@Override
public int getItemCount() {
return chatMsgModals.size();
}
public static class UserViewHolder extends RecyclerView.ViewHolder{
TextView userTv;
public UserViewHolder(@NonNull View itemView) {
super(itemView);
userTv = itemView.findViewById(R.id.idTvUser);
}
}
public static class BotViewHolder extends RecyclerView.ViewHolder{
TextView idTVBot;
public BotViewHolder(@NonNull View itemView) {
super(itemView);
idTVBot = itemView.findViewById(R.id.idTVBot);
}
}
}
package com.project.skidn_disease_app.model;
public class MsgModal {
private String msg;
private boolean success;
public MsgModal(String msg, boolean success) {
this.msg = msg;
this.success = success;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment