package com.app.simplitend.chats;

import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.app.simplitend.R;
import com.app.simplitend.chats.mvvm.Message;
import com.bumptech.glide.Glide;
import com.stfalcon.chatkit.messages.MessagesListAdapter;

import de.hdodenhof.circleimageview.CircleImageView;

public class ReceiverViewHolder extends MessagesListAdapter.OutcomingMessageViewHolder<Message> {

    protected TextView message_txt;
    protected CircleImageView avatar;

    public ReceiverViewHolder(View itemView) {
        super(itemView);
        message_txt = itemView.findViewById(R.id.messageText);
        avatar = itemView.findViewById(R.id.messageUserAvatar_receiver);
    }

    @Override
    public void onBind(Message message) {
        super.onBind(message);
        message_txt.setText(message.getText());
        message_txt.setTextColor(Color.BLACK);

        try {
            try {
                int res = Integer.parseInt(message.getUser().getAvatar());
                avatar.setImageResource(res);
            }catch (Exception e){
                if (message.getUser().getAvatar() != null){
                    Glide.with(avatar.getContext())
                            .load(message.getUser().getAvatar())
                            .placeholder(android.R.color.darker_gray)
                            .error(android.R.color.darker_gray)
                            .into(avatar);
                }
            }
        }catch (Exception e){
            // do nothing
        }
    }
}
