package com.swago.user.task

import android.content.Context
import android.graphics.Color
import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.swago.baseswago.GradientIndicator
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.user.R
import com.swago.user.databinding.ActivityTaskBinding
import com.swago.user.vm.TaskVm
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.titles.SimplePagerTitleView

/**
 *@date 2021/11/25 21:18
 *description:
 */
@Route(path = ARouteConstant.User.taskCenter)
class TaskActivity : BaseXActivity<ActivityTaskBinding>(){

    override fun loadData() {
    }

    override fun initOther() {
        setBackView(binding.toolbar.ivBack)
        binding.toolbar.tvTitle.text = AppContext.getContext().resources.getString(R.string.task_center)


        val listFragments = arrayListOf(DailyFragment(), NewerFragment())
        val listTitles = arrayListOf(AppContext.getContext().resources.getString(R.string.daily_task),AppContext.getContext().resources.getString(R.string.newer_task))
        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("#000000")
                simplePagerTitleView.setOnClickListener {
                    binding.viewPager.currentItem = index
                }
                return simplePagerTitleView
            }

            override fun getIndicator(context: Context?): IPagerIndicator {
                val indicator = GradientIndicator(context)
                indicator.mode = GradientIndicator.MODE_EXACTLY
                indicator.lineWidth = DpPxUtil.dip2px(72f).toFloat()
                indicator.xOffset = DpPxUtil.dip2px(5f).toFloat()
                indicator.yOffset = DpPxUtil.dip2px(17f).toFloat()
                indicator.lineHeight = DpPxUtil.dip2px(8f).toFloat()
                indicator.roundRadius = DpPxUtil.dip2px(2f).toFloat()
                return indicator
            }

        }

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

    }

    override fun initLiveData() {}
}