package com.tenlionsoft.baselib.core.widget.base;

import android.content.Context;
import android.graphics.Color;

import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.BezierPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;

import java.util.List;

import androidx.viewpager2.widget.ViewPager2;

/**
 * 作者: adam
 * 日期: 2021/11/4 - 3:17 下午
 * 邮箱: itgaojian@163.com
 * 描述: viewpage2简单指示器
 */
public class ViewPageNavigatorAdapter extends CommonNavigatorAdapter {
    private List<String> mTitles;
    private Context mContext;
    private ViewPager2 mVp;

    public ViewPageNavigatorAdapter(Context ctx, List<String> titles, ViewPager2 vp) {
        this.mTitles = titles;
        this.mContext = ctx;
        this.mVp = vp;
    }

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

    @Override
    public IPagerTitleView getTitleView(Context context, int index) {
        ColorTransitionPagerTitleView cView = new ColorTransitionPagerTitleView(context);
        cView.setNormalColor(Color.GRAY);
        cView.setSelectedColor(Color.parseColor("#2262FB"));
        cView.setText(mTitles.get(index));
        cView.setTextSize(16F);
        cView.setOnClickListener(v -> mVp.setCurrentItem(index));
        return cView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
//        BezierPagerIndicator indicator = new BezierPagerIndicator(context);
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
        indicator.setColors(Color.parseColor("#2262FB"));
        return indicator;
    }
}
