package com.itant.indicator;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;


import com.shizhefei.view.indicator.IndicatorViewPager;

import java.util.List;

/**
 * 指示器的适配器
 */
public class ColorfulIndicatorAdapter extends IndicatorViewPager.IndicatorFragmentPagerAdapter {

        private LayoutInflater inflater;
        private List<Fragment> fragmentList;

        public ColorfulIndicatorAdapter(FragmentManager fragmentManager,
                                        List<Fragment> fragmentList, LayoutInflater inflater) {
            super(fragmentManager);
            this.inflater = inflater;
            this.fragmentList = fragmentList;
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }

        @Override
        public View getViewForTab(int position, View convertView, ViewGroup container) {
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.indicator_item, container, false);
            }
            return convertView;
        }

        @Override
        public Fragment getFragmentForPage(int position) {
            return fragmentList.get(position);
        }
    }