package com.itant.joycity.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itant.joycity.R;
import com.itant.joycity.bean.GridImageTextBean;
import com.itant.joycity.bean.VideoItem;

import java.util.List;

/**
 * Created by Jason on 2016/10/6.
 * 图片列表适配器
 */
public class VideoAdapter extends BaseAdapter {

    private List<VideoItem> videoItems;
    private Context context;

    public void setVideoItems(List<VideoItem> videoItems) {
        this.videoItems = videoItems;
    }

    public VideoAdapter() {

    }

    public VideoAdapter(Context context, List<VideoItem> videoItems) {
        this.videoItems = videoItems;
        this.context = context;
    }



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

    @Override
    public Object getItem(int position) {
        return videoItems == null ? null : videoItems.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VideoItem videoItem = videoItems.get(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_video, null);
            viewHolder = new ViewHolder();
            viewHolder.iv_video_poster = (ImageView) convertView.findViewById(R.id.iv_video_poster);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }



        viewHolder.iv_video_poster.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 点击按钮
                Intent intent= new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse("http://www.baidu.com");
                intent.setData(content_url);
                context.startActivity(intent);
            }
        });

        return convertView;
    }

    private ViewHolder viewHolder;
    private static class ViewHolder {
        ImageView iv_video_poster;
        TextView tv_title;
    }
}
