package com.tenlionsoft.baselib.core.widget.views;

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

import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.FuncBean;

import java.util.List;

public class FuncBtnAdapter extends BaseAdapter {
    private Context mContext;
    private List<FuncBean> mDatas;

    public FuncBtnAdapter(Context ctx, List<FuncBean> datas) {
        this.mContext = ctx;
        this.mDatas = datas;
    }

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

    @Override
    public FuncBean getItem(int position) {
        return mDatas.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        FuncHolder funcHolder;
        if (convertView == null) {
            funcHolder = new FuncHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_btn_func, parent, false);
            funcHolder.mIvFunc = convertView.findViewById(R.id.iv_func_img);
            funcHolder.mTvTitle = convertView.findViewById(R.id.tv_func_text);
            funcHolder.mLlContent = convertView.findViewById(R.id.ll_func_btn);
            convertView.setTag(funcHolder);
        } else {
            funcHolder = (FuncHolder) convertView.getTag();
        }
        funcHolder.mIvFunc.setImageResource(mDatas.get(position).getIconRes());
        funcHolder.mTvTitle.setText(mDatas.get(position).getText());
        switch (position) {
            case 0:
                funcHolder.mLlContent.setBackgroundResource(R.drawable.shape_btn_blue);
                break;
            case 1:
                funcHolder.mLlContent.setBackgroundResource(R.drawable.shape_btn_green_shallow);
                break;
            case 2:
                funcHolder.mLlContent.setBackgroundResource(R.drawable.shape_btn_yellow);
                break;
            case 3:
                funcHolder.mLlContent.setBackgroundResource(R.drawable.shape_btn_purple);
                break;
            case 4:
                funcHolder.mLlContent.setBackgroundResource(R.drawable.shape_btn_green);
                break;
        }
        return convertView;
    }

    static class FuncHolder {
        ImageView mIvFunc;
        TextView mTvTitle;
        LinearLayout mLlContent;
    }
}
