package cn.yyxx.eyuangame.core.impl.login

import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import cn.yyxx.eyuangame.core.impl.login.fragment.LauncherFragment
import cn.yyxx.eyuangame.core.impl.login.fragment.RegisterFragment

/**
 * @author #Suyghur.
 * Created on 2021/06/18
 */
class LoginFragmentPagerAdapter constructor(private val titles: Array<String>, fm: FragmentManager, behavior: Int = 0) : FragmentPagerAdapter(fm, behavior) {

    var currentFragment: Fragment? = null
        private set

    override fun getCount(): Int {
        return titles.size
    }

    override fun getItem(position: Int): Fragment {
        return if (position == 1) {
            RegisterFragment()
        } else {
            LauncherFragment()
        }
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return titles[position]
    }

    override fun setPrimaryItem(container: ViewGroup, position: Int, `object`: Any) {
        currentFragment = `object` as Fragment
        super.setPrimaryItem(container, position, `object`)
    }

}