package com.kaixed.kchat.view.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.kaixed.kchat.R;
import com.kaixed.kchat.model.HomeItem;

import java.util.List;

/**
 * @author kaixed
 */
public class MyGridAdapter extends BaseAdapter {
    private Context context;
    private List<HomeItem> items;

    public MyGridAdapter(Context context, List<HomeItem> items) {
        this.context = context;
        this.items = items;
    }

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

    @Override
    public Object getItem(int position) {
        return items.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(context).inflate(R.layout.item_grid, parent, false);
        }


        HomeItem item = items.get(position);

        TextView title = convertView.findViewById(R.id.textview);
        ImageView image = convertView.findViewById(R.id.imageview);
        ImageView imageView = convertView.findViewById(R.id.iv_more);

        if (item.getMore()) {
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }

        title.setText(item.getName());
        image.setImageResource(item.getImg());

        return convertView;
    }
}
