package com.tofly.ghrq_route.common.ui.adapter;

import android.app.Activity;
import android.view.View;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.tofly.ghrq_route.common.ui.view.BigImageView;

import java.util.List;

public class BigImageAdapter extends PagerAdapter {

    private Activity mContext;
    private View views[];
    private List<String> imagePaths;

    public BigImageAdapter(Activity context, List<String> pics, BigImageView.OnMovingListener movingListener){
        mContext = context;
        imagePaths = pics;
        int pages = pics.size();
        views = new View[pages];
        for (int i = 0; i < pages; i++){
            String picPath = pics.get(i);
            BigImageView bigImageView = new BigImageView(context, picPath, movingListener);
            views[i] = bigImageView;
        }
    }

    public View getView(int postion){
        return views[postion];
    }

    @Override
    public int getCount() {
        return views.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    public void destroyItem(View container, int position, Object object) {
        ((ViewPager) container).removeView(views[position]);
    }

    public Object instantiateItem(View container, int position) {
        ((ViewPager) container).addView(views[position]);
        return views[position];
    }
}
