package com.zj365.dc.activity

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.BaseListAct
import com.xty.common.UmengEventId
import com.xty.common.arouter.ARouterUrl
import com.xty.common.arouter.RouteManager
import com.xty.common.onEventObject
import com.xty.network.model.ScienceBean
import com.zj365.dc.adapter.ScienceAdapter
import com.zj365.dc.vm.HomeVm
import com.zj365.health.databinding.ActDataListBinding

@Route(path = ARouterUrl.SCIENCE_LIST)
class HealthScienceAct : BaseListAct<HomeVm> (){

    val binding by lazy { ActDataListBinding.inflate(layoutInflater) }

    val adapterSince by lazy { ScienceAdapter() }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)
        binding.title.mTvTitle.text ="健康科普"
        binding.title.mIvBack.setOnClickListener {
            finish()
        }
    }

    override fun initAdapter() {
        binding.mRecycle.layoutManager = LinearLayoutManager(this)
        binding.mRecycle.adapter = adapterSince
        adapterSince.setOnItemClickListener { adapter, view, position ->
            bundle.clear()
            var bean = adapter.getItem(position) as ScienceBean
            bundle.putSerializable("bean", bean)
            onEventObject(this, UmengEventId.HealthScience, "${bean.name}")
            RouteManager.goAct(ARouterUrl.SCIENCE_DETAIL, bundle)

        }
    }

    override fun loadData() {

        mViewModel.getScinceList()
    }

    override fun liveObserver() {
        mViewModel.scinceLive.observe(this) {
            adapterSince.setNewInstance(it.data)
        }
    }

    override fun setLayout() = binding.root
}