package com.xty.server.act

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseListAct
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.recycleUtils.RecycleItem
import com.xty.network.model.GuidBean
import com.xty.server.R
import com.xty.server.adapter.GuideAdapter
import com.xty.server.databinding.ActGuildBinding
import com.xty.server.vm.GuideVm

/**
 * 操作指南列表
 */
@Route(path = ARouterUrl.GUIDE)
class GuideAct: BaseListAct<GuideVm>() {
    val mAdapter by lazy{ GuideAdapter() }
    val binding by lazy{ ActGuildBinding.inflate(layoutInflater)}
    override fun initData() {
        super.initData()
        isDarkBar=true
    }
    override fun initAdapter() {
        binding.mRecycle.adapter=mAdapter
        binding.mRecycle.layoutManager=LinearLayoutManager(this)
        binding.mRecycle.addItemDecoration(RecycleItem(this,10))
        mAdapter.setOnItemClickListener { adapter, view, position ->
            val  item = adapter.getItem(position) as GuidBean
            bundle.clear()
            bundle.putSerializable("bean",item)
            RouteManager.goAct(ARouterUrl.GUIDE_DETAIL,bundle)
        }
    }


    override fun setLayout()=binding.root
    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener { finish() }
        binding.title.mTvTitle.text=getString(R.string.guid_operation)
        setRecycleRefresh(binding.mRecycle,binding.mRefresh)
    }
    override fun loadData() {
        mViewModel.getGuideList()
    }

    override fun liveObserver() {
        mViewModel.guidLive.observe(this){
            setDate(mAdapter,it.data)
        }
    }
}