package com.sheep.gamegroup.helper;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
import com.kfzs.appstore.utils.adapter.recyclerview.ViewHolder;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;

import java.util.ArrayList; /**
 * Created by realicing on 2018/7/5.
 * realicing@sina.com
 */
public class ImageListHelper {
    public static void initList(final Activity activity, final RecyclerView recyclerView, final ArrayList<String> pictureList) {
        recyclerView.setVisibility(View.VISIBLE);
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        recyclerView.setNestedScrollingEnabled(false);

        RecyclerViewAdapter mRecyclerViewAdapter = new RecyclerViewAdapter<String>(recyclerView.getContext(), R.layout.item_image, pictureList) {
            @Override
            public void convert(ViewHolder viewHolder, String url, final int position) {
                View view = viewHolder.getView(R.id.img_detail);
                if (view instanceof ImageView) {
                    try {
                        Glide.with(SheepApp.getInstance()).load(url).into((ImageView) view);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    view.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Jump2View.getInstance().showImgList(activity, position, pictureList);
                        }
                    });
                }

            }
        };
        recyclerView.setAdapter(mRecyclerViewAdapter);
    }
}
