package com.bokecc.livemodule.live.function.lottery.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bokecc.dwlivedemo.R;
import com.bokecc.livemodule.utils.ImageLoader;
import com.bokecc.sdk.mobile.live.pojo.LotteryUserInfo;


public class TimeChooseItemView extends FrameLayout {
    private int mHeight;
    private LotteryUserInfo mLotteryUserInfo;
    private ImageView imageView;
    private TextView name;

    public TimeChooseItemView(Context context) {
        super(context);
        init();
    }

    public TimeChooseItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TimeChooseItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public LotteryUserInfo getData() {
        return mLotteryUserInfo;
    }

    public void setData(LotteryUserInfo mLotteryUserInfo) {
        this.mLotteryUserInfo = mLotteryUserInfo;
        if (!TextUtils.isEmpty(mLotteryUserInfo.getUserAvatar())){
            ImageLoader.loadIntoImageView(getContext().getApplicationContext(),mLotteryUserInfo.getUserAvatar(),imageView,R.drawable.head_view_publisher,R.drawable.head_view_publisher);
        } else {
            ImageLoader.loadIntoImageView(getContext().getApplicationContext(),mLotteryUserInfo.getLocalavatar(),imageView,R.drawable.head_view_publisher,R.drawable.head_view_publisher);
        }

        if (!TextUtils.isEmpty(mLotteryUserInfo.getUserName())){
            name.setText(mLotteryUserInfo.getUserName());
        } else {
            name.setText("");
        }
    }

    protected void setItemHeight(int height) {
        mHeight = height;
    }

    protected void setItemSelected(boolean selected) {}

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
    }

    private void init() {
        View view = View.inflate(getContext(), R.layout.item_dialog_tiger_img,this);
        imageView = findViewById(R.id.user_image);
        name = findViewById(R.id.userName);
    }
}
