package com.quansu.heifengwuliu.activity

import android.graphics.Color
import android.os.Bundle
import androidx.core.content.ContextCompat
import com.quansu.heifengwuliu.R
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.databinding.ActivityHomeBinding
import com.quansu.heifengwuliu.fragment.DeliverGoodsFragment
import com.quansu.heifengwuliu.fragment.MineFragment
import com.quansu.heifengwuliu.fragment.WayBillFragment
import com.quansu.heifengwuliu.repository.HomeRepository
import com.quansu.heifengwuliu.vmodel.HomeVModel
import com.ysnows.base.base.BRepository

/**
 * 首页
 *Created by shihuiyun
 *on 2020/9/9
 */
class HomeActivity : MBActivity<HomeVModel, ActivityHomeBinding>() {

    //默认为0
    private var mIndex = 0

    override fun binding(): ActivityHomeBinding {
        return ActivityHomeBinding.inflate(layoutInflater)

    }

    override fun initCreate(savedInstanceState: Bundle?) {
        if (savedInstanceState != null) {
            mIndex = savedInstanceState.getInt("currTabIndex")
        }
        super.initCreate(savedInstanceState)
        initMainMenu()
        binding.mainMenu.switchTab(0)
    }

    override fun vmClass(): Class<HomeVModel> {
        return HomeVModel::class.java
    }

    override fun createRepository(): BRepository {
        return HomeRepository()
    }

    override fun title(): String? {
        return null
    }


    private fun initMainMenu() {

        // val oneFragment = IndexFragment()
        val oneFragment = DeliverGoodsFragment()
        val twoFragment = WayBillFragment()
        val threeFragment = MineFragment()
        val menuTabBuilder = binding.mainMenu.tabBuilder()
                .setSelectColor(Color.parseColor("#2E4E71"))
                .setNormalColor(Color.parseColor("#666666"))
        val one = menuTabBuilder
                .setFragment(oneFragment)
                .setNormalDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_index))
                .setSelectedDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_index_focus))
                .setText(getString(R.string.home))
                .build(context())
        val two = menuTabBuilder
                .setFragment(twoFragment)
                .setNormalDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_vehicle))
                .setSelectedDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_vehicle_focus))
                .setText(getString(R.string.waybill))
                .build(context())
        val three = menuTabBuilder
                .setFragment(threeFragment)
                .setText(getString(R.string.my))
                .setNormalDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_tyre))
                .setSelectedDrawable(ContextCompat.getDrawable(context(), R.drawable.menu_tyre_focus))
                .build(context())

        binding.mainMenu
                .addTab(one)
                .addTab(two)
                .addTab(three)
                .rendor()
    }

    override val isRxbus: Boolean
        get() = true


}
