package com.zxhl.main.page.view

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.viewpager.widget.ViewPager
import com.zxhl.cms.common.FragmentAdapter
import com.zxhl.cms.common.base.BaseFragment
import com.zxhl.cms.widget.TabPagerIndicator
import com.zxhl.main.R

abstract class BaseViewPagerFragment : BaseFragment() {

    protected var viewPager: ViewPager? = null

    protected var tabLayout: TabPagerIndicator? = null


    protected var offscreenPageLimit = 1

    abstract val createTitles: ArrayList<String>

    abstract val createFragments: Array<BaseFragment>

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        setupViews()
    }

    override fun onDestroy() {
        super.onDestroy()
    }

    open fun setupViews() {
        initVeiwPager()
    }

    protected fun initVeiwPager() {
        viewPager = fragmentView?.findViewById(R.id.viewPager)
        tabLayout = fragmentView?.findViewById(R.id.id_fragment_home_tab)

        val adapter = FragmentAdapter(childFragmentManager)
        viewPager?.adapter = adapter

        for (i in createFragments.indices) {
            Log.d("glc",createTitles[i])
            adapter?.addFrag(createFragments[i], createTitles[i])
        }
        adapter?.notifyDataSetChanged()
        tabLayout?.setViewPager(viewPager)
        tabLayout?.setOverScrollMode(View.OVER_SCROLL_NEVER)
    }


}