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

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bokecc.dwlivedemo.R;
import com.bokecc.livemodule.live.DWLiveCoreHandler;
import com.bokecc.sdk.mobile.live.pojo.LotteryUserInfo;
import com.bumptech.glide.Glide;

import java.util.List;

public class OneArmHanditResultAdapter extends BaseAdapter {
    private List<LotteryUserInfo> users;
    private Context context;
    public OneArmHanditResultAdapter (Context context, List<LotteryUserInfo> users){
        this.users = users;
        this.context = context;
    }

    @Override
    public int getCount() {
        return users.size();
    }

    @Override
    public LotteryUserInfo getItem(int i) {
        return users.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View item = View.inflate(context, R.layout.item_one_arm_handit_result,null);
        ImageView userImage = item.findViewById(R.id.user_image);
        ImageView bg = item.findViewById(R.id.bg);
        TextView userName = item.findViewById(R.id.userName);

        LotteryUserInfo info = users.get(i);
        if (DWLiveCoreHandler.getInstance().getViewer().getId().equals(info.getUserId())){
            bg.setVisibility(View.VISIBLE);
            userName.setTextColor(Color.parseColor("#FF6E0A"));
        } else {
            bg.setVisibility(View.GONE);
            userName.setTextColor(Color.parseColor("#333333"));
        }
        userName.setText(info.getUserName());
        Glide.with(context)
                .load(info.getUserAvatar())
                .placeholder(R.drawable.head_view_publisher)
                .into(userImage);

        return item;
    }
}
