package cn.net.caoyao.cpzshandset.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.PiCiBean;
import cn.net.caoyao.cpzshandset.bean.ProductListBean;
import cn.net.caoyao.cpzshandset.common.config.Config;
import cn.net.caoyao.cpzshandset.service.presenter.LoginApis;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.ResponseBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class ProductListAdapter extends RecyclerView.Adapter {
    List<ProductListBean.DataBean> list;
    Context context;
    List<PiCiBean.DataBean> listRefresh=new ArrayList<>();
    public ProductListAdapter(List<ProductListBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_product, null,false);
        MyVIewHolder myVIewHolder=new MyVIewHolder(inflate);
        return myVIewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, @SuppressLint("RecyclerView") final int i) {
        final MyVIewHolder holder1=(MyVIewHolder) viewHolder;
        String productName = list.get(i).getProductName();
        final long id = list.get(i).getId();
        holder1.tv_product_name.setText(productName+"");
        holder1.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(i);
            }
        });
    }
    private PiCiListAdapter.JieKou listener;
    public interface JieKou{
        void onClick(int pos);
    }
    public void onClick(PiCiListAdapter.JieKou listener1){
        this.listener=listener1;
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyVIewHolder extends RecyclerView.ViewHolder {
        TextView tv_product_name;
        public MyVIewHolder(View itemView) {
            super(itemView);
            tv_product_name = itemView.findViewById(R.id.tv_product_name);

        }
    }
}
