package com.yidian.yac.newscontent.ui

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 com.yidian.yac.newscontent.adapter.SimpleHomeAdapter
import com.yidian.yac.newscontent.bean.SimpleItemBean
import kotlinx.android.synthetic.main.fragment_news_flash.*
import kotlinx.android.synthetic.main.fragment_subscription.refreshLayout

/**
 * 首页订阅Fragment
 */
class NewsFlashFragment:BaseFragment() {
    companion object{
        fun newInstance():NewsFlashFragment{
            val fragment = NewsFlashFragment()
            val args = bundleOf()
            fragment.arguments = args
            return fragment
        }
    }
    private val adapter: SimpleHomeAdapter by lazy { SimpleHomeAdapter() }
    override val contentViewId: Int
        get() = R.layout.fragment_news_flash

    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)
        rv_stream.adapter = BaseHeaderAdapter(
            adapter,
            R.layout.activity_news_content
        )
    }

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

        adapter.setData(list)

    }

}