package com.yidian.yac.newscontent.template

import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import com.yidian.common.base.BaseFragment
import com.yidian.yac.newscontent.R
import com.yidian.common.base.BaseHeaderAdapter
import kotlinx.android.synthetic.main.fragment_news_flash.*
import kotlinx.android.synthetic.main.fragment_subscription.refreshLayout

/**
 * 模版Fragment
 */
class TemplateFragment:BaseFragment() {
    companion object{
        fun newInstance():TemplateFragment{
            val fragment = TemplateFragment()
            val args = bundleOf()
            fragment.arguments = args
            return fragment
        }
    }
    private val adapter: TemplateAdapter by lazy { TemplateAdapter() }
    override val contentViewId: Int
        get() = R.layout.fragment_template

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        initView()
        initData()
    }



    private fun initView() {
        refreshLayout.setOnRefreshListener { refreshHeader ->
            refreshHeader.finishRefresh(2000)
        }
        refreshLayout.setOnLoadMoreListener { refreshFooter ->
            refreshFooter.finishLoadMore(2000)
        }
        rv_stream.layoutManager = LinearLayoutManager(activity)
        //TODO 使用BaseHeaderAdapter代理原adapter并传入headerview（resId或view对象）
        rv_stream.adapter = BaseHeaderAdapter(adapter, R.layout.activity_news_content)
    }

    private fun initData() {
        val list = ArrayList<TemplateItemBean>()
        repeat(15){
            when(it){
                3 -> list.add(TemplateItemBean(380, "content $it"))
                6 -> list.add(TemplateItemBean(375, "content $it"))
                9 -> list.add(TemplateItemBean(377, "content $it"))
                else->list.add(TemplateItemBean(0, "content $it"))
            }
        }

        adapter.setData(list)

    }

}