package com.swago.user.level

import android.content.Context
import android.graphics.Color
import com.alibaba.android.arouter.facade.annotation.Route
import com.swago.baseswago.SwagoAdapter
import com.swago.baseswago.activity.BaseXActivity
import com.swago.baseswago.constant.ARouteConstant
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.DpPxUtil
import com.swago.baseswago.util.NoDoubleClickListener
import com.swago.user.R
import com.swago.user.databinding.ActivityLevelBinding
import net.lucode.hackware.magicindicator.ViewPagerHelper
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
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.LinePagerIndicator
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView

/**
 *@date 2021/11/21 11:15
 *description:
 */
@Route(path = ARouteConstant.User.level)
class LevelActivity : BaseXActivity<ActivityLevelBinding>(){

    override fun loadData() {}

    override fun initOther() {
        binding.ivBack.setOnClickListener(object:NoDoubleClickListener(){
            override fun onClick() {
                finish()
            }
        })

        val listFragments = arrayListOf(RichLevelFragment(),AnchorLevelFragment())
        val listTitles = arrayListOf(AppContext.getContext().resources.getString(R.string.rich_level),AppContext.getContext().resources.getString(R.string.anchor_level))
        binding.viewPager.offscreenPageLimit = 3
        val viewPagerAdapter = SwagoAdapter(listFragments,supportFragmentManager,listTitles)
        binding.viewPager.adapter = viewPagerAdapter

        val commonNavigator = CommonNavigator(this)
        commonNavigator.isAdjustMode = true
        commonNavigator.adapter = object:CommonNavigatorAdapter(){
            override fun getCount(): Int {
                return listTitles.size
            }

            override fun getTitleView(context: Context, index: Int): IPagerTitleView {
                val simplePagerTitleView = SimplePagerTitleView(context)
                simplePagerTitleView.text = listTitles[index]
                simplePagerTitleView.textSize = 16f
                simplePagerTitleView.normalColor = Color.parseColor("#868686")
                simplePagerTitleView.selectedColor = Color.parseColor("#ffffff")
                simplePagerTitleView.setOnClickListener {
                    binding.viewPager.currentItem = index
                }
                return simplePagerTitleView
            }

            override fun getIndicator(context: Context?): IPagerIndicator {
                val indicator = LinePagerIndicator(context)
                indicator.lineHeight = 0f
                return indicator
            }

        }

        binding.magicIndicator.navigator = commonNavigator
        ViewPagerHelper.bind(binding.magicIndicator,binding.viewPager)

    }

    override fun initLiveData() {

    }
}