package com.gh.gamecenter.gamedetail;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.gh.common.util.DataUtils;
import com.gh.common.util.ImageUtils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.ViewImageActivity;
import com.gh.gamecenter.manager.DataCollectionManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by LGT on 2016/9/8.
 */
public class GameGalleryAdapter extends RecyclerView.Adapter<GameGalleryViewHolder> {

	private Context context;

	private ArrayList<String> gallery;

	public GameGalleryAdapter(Context context, ArrayList<String> list) {
		this.context = context;
		gallery = list;
	}

	@Override
	public GameGalleryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View inflate = LayoutInflater.from(parent.getContext())
				.inflate(R.layout.gamedetail_screenshot_item, parent, false);
		return new GameGalleryViewHolder(inflate);
	}

	@Override
	public void onBindViewHolder(final GameGalleryViewHolder holder, int position) {
		ImageUtils.getInstance(context).display(gallery.get(position), holder.screenshot_item_iv);
		holder.itemView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Map<String, Object> kv = new HashMap<>();
				kv.put("位置", String.valueOf(holder.getPosition() + 1));
				DataUtils.onEvent(context, "点击", "游戏详情-游戏介绍", kv);

				Map<String, Object> map = new HashMap<>();
				map.put("location", "游戏介绍");
				map.put("page", "游戏详情");
				DataCollectionManager.onEvent(context, "click-item", map);

				Intent intent = new Intent(context, ViewImageActivity.class);
				intent.putExtra("urls", gallery);
				intent.putExtra("current", holder.getPosition());
				context.startActivity(intent);
			}
		});
	}

	@Override
	public int getItemCount() {
		return gallery.size();
	}

}
