package com.swago.home.official

import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.swago.baseswago.activity.BaseListActivity
import com.swago.baseswago.cusview.SwagoRecyclerView
import com.swago.baseswago.model.home.OfficialMsgModel
import com.swago.baseswago.util.AppContext
import com.swago.home.R
import com.swago.home.databinding.ActivityOfficialMessageBinding

/**
 *@date 2021/11/20 13:38
 *description:
 */
class OfficialMessageActivity : BaseListActivity<ActivityOfficialMessageBinding, OfficialMsgModel.ListBean>() {

    private val officialVm by viewModels<OfficialVm>()

    override val smartRecyclerView: SwagoRecyclerView<OfficialMsgModel.ListBean> by lazy {
        binding.swagoRv as SwagoRecyclerView<OfficialMsgModel.ListBean>
    }
    override val adapter: BaseQuickAdapter<OfficialMsgModel.ListBean, *> by lazy {
        OfficialAdapter()
    }
    override val layoutManager: RecyclerView.LayoutManager by lazy {
        LinearLayoutManager(this)
    }
    override val loadData: (page: Int) -> Unit = {
        officialVm.getMsgList(it+1)
    }

    override fun initViewData() {
        setBackView(binding.toolbar.ivBack)
        binding.toolbar.tvTitle.text = AppContext.getContext().resources.getString(R.string.swago_offical_msg)
    }

    override fun initLiveData() {
        officialVm.listMsgLiveData.observe(this){
            if (it == null){
                smartRecyclerView.onFetchDataError()
            }else{
                smartRecyclerView.onFetchDataFinish(it,true)
            }
        }
    }
}