package com.swago.baseswago.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.swago.baseswago.cusview.SwagoRecyclerView

/**
 *@date 2021/11/28 10:41
 *description:
 */
abstract class BaseListFragment<T: ViewBinding,E>: BaseFragment<T>() {

    private val preLoadPage = 1
    abstract val smartRecyclerView: SwagoRecyclerView<E>
    abstract val adapter: BaseQuickAdapter<E, *>
    abstract val layoutManager: RecyclerView.LayoutManager

    abstract val loadData:((page:Int)->Unit)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        smartRecyclerView.recyclerView?.layoutManager = layoutManager
        smartRecyclerView.setSmartRefreshUtil(
            adapter,preLoadPage,loadMoreNeed(),refreshNeed(),loadData
        )
        initViewData()
        initLiveData()
        if (isRefreshAtOnStart()){
            smartRecyclerView.startRefresh()
        }
    }

    abstract fun initViewData()
    abstract fun initLiveData()

    open fun loadMoreNeed(): Boolean {
        return true
    }

    open fun refreshNeed(): Boolean {
        return true
    }

    open fun isRefreshAtOnStart():Boolean{
        return true
    }

}