package com.zj365.mime.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import com.xty.base.fragment.BaseFragList
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.recycleUtils.RecycleItem 
import com.zj365.mime.adapter.SportAdapter
import com.zj365.mime.R
import com.zj365.mime.databinding.FragProgrammeSportBinding
import com.zj365.mime.vm.MyProgVm
import com.xty.network.model.SportBean
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
* 运动数据列表
*/
class ProgrammeSportFrag : BaseFragList<MyProgVm>(){
    val binding by lazy { FragProgrammeSportBinding.inflate(layoutInflater) }
    val mAdapter by lazy { SportAdapter() }

    var userId:String?=null
    override fun initAdapter() {
        setRecycleRefresh(binding.mRecycle, binding.mRefresh,true)
        binding.mRecycle.addItemDecoration(RecycleItem(requireContext(), 40))
        binding.mRecycle.layoutManager = LinearLayoutManager(requireContext())
        binding.mRecycle.adapter = mAdapter

        mAdapter.setOnItemClickListener { adapter, view, position ->
           var bean= adapter.getItem(position) as SportBean
            bundle.clear()
            bundle.putString("id",bean.id.toString())
            RouteManager.goAct(ARouterUrl.SPORT_DETAIL, bundle)
        }
    }

    override fun initData() {
        super.initData()
        userId = arguments?.getString("userId")
    }

    override fun refresh() {
        mViewModel.getSportListNew(page,userId)
    }

    override fun setViewModel()=MyProgVm()

    override fun observer() {
        mViewModel.sportLive.observe(this) {
            setDate(mAdapter,it.data)
        }
    }

    override fun setLayout()= binding.root

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun refreshList(str:String){
        when(str){
            "refresh"->{
                page=1
                refresh()
            }
        }
    }
}