package com.yutou.jianr_mg.Adapters.GameDataAdapters;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.yutou.jianr_mg.R;
import com.yutou.jianr_mg.Tools.Utils;

import java.util.Map;

import cn.lemon.view.adapter.BaseViewHolder;
import cn.lemon.view.adapter.RecyclerAdapter;

public class DropAdapter extends RecyclerAdapter<Map<String,String>> {
    ImageLoader loader;
    public DropAdapter(Context context) {
        super(context);
        loader= Utils.initImageLoader(context);
    }

    @Override
    public BaseViewHolder<Map<String, String>> onCreateBaseViewHolder(ViewGroup parent, int viewType) {
        return new MyHolder(parent, R.layout.item_team);
    }
    class MyHolder extends BaseViewHolder<Map<String,String>>{
        private ImageView icon;
        private LinearLayout layout,hpLayout;
        private TextView name,time;
        private ProgressBar itemHp;
        MyHolder(ViewGroup parent, int layoutId) {
            super(parent, layoutId);
            icon=findViewById(R.id.icon);
            layout=findViewById(R.id.items);
            hpLayout=findViewById(R.id.hpLayout);
            name=findViewById(R.id.title);
            itemHp=findViewById(R.id.itemHp);
            layout.setVisibility(View.GONE);
            itemHp.setVisibility(View.GONE);
            hpLayout.removeAllViews();
            time=new TextView(getContext());
            hpLayout.addView(time);
        }

        @Override
        public void setData(Map<String, String> data) {
            super.setData(data);
            name.setText(data.get("name"));
            time.setText(data.get("time"));
            if(data.containsKey("icon")){
                loader.displayImage(data.get("icon"),icon);
            }else{
                icon.setImageResource(R.mipmap.icon_logo);
            }
        }
    }
}
