package com.stu.assistant.adapter;

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.TextView;

import com.stu.assistant.R;
import com.stu.assistant.base.BaseApplion;
import com.stu.assistant.bean.MainModuleBean;
import com.stu.assistant.uitls.ImageUtil;

import java.util.ArrayList;

public class HomeGvAdapter extends BaseAdapter {

    private Context mContext;
    private ViewHolder holder;
    private ArrayList<MainModuleBean> list;

    public HomeGvAdapter(Context context, ArrayList<MainModuleBean> moduleBeansList) {
        mContext = context;
        this.list = moduleBeansList;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gridview, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ImageUtil.showImageView(BaseApplion.application,list.get(position).getImageView(), holder.mImageView);
        holder.mTextView.setText(list.get(position).getName());
        return convertView;
    }

    class ViewHolder {
        private ImageView mImageView;
        private TextView mTextView;

        public ViewHolder(View convertView) {
            mImageView = (ImageView) convertView.findViewById(R.id.img_into);
            mTextView = (TextView) convertView.findViewById(R.id.tv);
        }
    }
}
