package com.cygnusa.hyperm.adapter;


import android.app.Activity;
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 com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.cygnusa.hyperm.R;
import com.cygnusa.hyperm.wrappers.GetAllExploreImageList;

import java.util.List;

public class ProductListAdapter extends BaseAdapter {
    private Context context;
    private List<GetAllExploreImageList> data;

    public ProductListAdapter(Context context, List<GetAllExploreImageList> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {

        return data.size()+1;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            convertView = inflater.inflate(
                    R.layout.grid_item_layout, null);
            holder.image = convertView.findViewById(R.id.image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (position == data.size()) {
            Glide.with(context).load(R.drawable.coming_soon_1)
                    .thumbnail(Glide.with(context).load(R.drawable.coming_soon_1))
                    .apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.ALL)
                            .placeholder(R.drawable.placeholder)).into(holder.image);
        } else {
            Glide.with(context).load(data.get(position).getModelEnquiryUrl())
                    .thumbnail(Glide.with(context).load(R.drawable.gif_loader))
                    .apply(new RequestOptions().fitCenter().diskCacheStrategy(DiskCacheStrategy.ALL)
                            .placeholder(R.drawable.placeholder)).into(holder.image);
        }

        return convertView;
    }

    static class ViewHolder {
        ImageView image;
    }
}


