package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.data.model.MemberInfoData;
import kr.co.hanwha.hifive.util.GlideUtil;

/**
 * Created by sanghoonkwon on 2018. 1. 19..
 */

public class HFReceiverView extends LinearLayout {
    private ImageView mImageViewReceiver;
    private TextView mTextViewReceiver;

    public HFReceiverView(Context context) {
        super(context);
        initialize(context, null);
    }

    public HFReceiverView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public HFReceiverView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, @Nullable AttributeSet attrs) {
        if (isInEditMode()) return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_receiver, this, true);

        mImageViewReceiver = (ImageView) findViewById(R.id.receiver_imageView);
        mTextViewReceiver = (TextView) findViewById(R.id.receiver_textView);

        GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.ic_avatar, mImageViewReceiver);
    }

    public void setMemberInfo(@NonNull MemberInfoData data) {
        if (TextUtils.isEmpty(data.getProfile_url()))
            GlideUtil.getInstance().loadImageCircle(getContext(), R.mipmap.ic_avatar, mImageViewReceiver);
        else
            GlideUtil.getInstance().loadImageCircle(getContext(), data.getProfile_url(), mImageViewReceiver);

        mTextViewReceiver.setText(TextUtils.isEmpty(data.getMember_name()) ? "" : data.getMember_name());
    }
}