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

import android.content.Context;
import android.view.View;
import android.widget.ListView;

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

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.tofly.ghrq_route.R;

import java.util.List;

/**
 * Created by dhc on 16/6/23.
 */
public class DangerPageAdapter extends PagerAdapter {
    private Context mContext;
    private View views[];
    private List<String> mLabels;
    private PullToRefreshListView pullToRefreshListView;

    public DangerPageAdapter(Context context, List<String> labels){
        mContext = context;
        mLabels = labels;
        int pages = labels.size();
        views = new View[pages];
        for (int i = 0;  i < pages; i++){
            View rootView = View.inflate(context, R.layout.ui_danger_page, null);
            views[i] = rootView;
        }
    }

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

    public PullToRefreshListView getPullRefreshView(int position){
        PullToRefreshListView refreshListView = null;
        View view = views[position];
        if (view != null){
            refreshListView = (PullToRefreshListView) view.findViewById(R.id.reported_lv);
        }
        return refreshListView;
    }

    public ListView getListView(int position){
        ListView listView = null;
        View view = views[position];
        if (view != null){
            PullToRefreshListView pullToRefreshListView = (PullToRefreshListView) view.findViewById(R.id.reported_lv);
            listView = pullToRefreshListView.getRefreshableView();
        }
        return listView;
    }

    @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];
    }
}
