riku
2021-02-25 e102578ebfc95c27aeb13dce13fb82af53a2bead
app/src/main/java/cn/flightfeather/thirdapp/view/recyclerview/RecyclerViewSetInterface.kt
@@ -5,6 +5,8 @@
import android.view.ViewGroup
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.loadmore.LoadMoreView
import com.chad.library.adapter.base.loadmore.SimpleLoadMoreView
/**
 * @author riku
@@ -65,7 +67,7 @@
            //设置空布局
            getMyLoadingView()?.let { emptyView = it }
//            setLoadMoreView(SimpleLoadMoreView())
            getLoadMoreView()?.let { setLoadMoreView(it)}
        }
        //加载更多
        setLoadMore()
@@ -117,7 +119,7 @@
    /**
     * 将列表数据替换成新的数据
     */
    fun setNewData(dataList: ArrayList<T>) {
    fun setNewData(dataList: List<T>) {
        val resultList = convertToSection(dataList)
        addSection(resultList)
        adapter?.setNewData(resultList)
@@ -127,14 +129,14 @@
    /**
     * 在原数据基础上添加新数据
     */
    fun addData(dataList: ArrayList<T>) {
    fun addData(dataList: List<T>) {
        val resultList = convertToSection(dataList)
        addSection(resultList)
        adapter?.addData(resultList)
        onDataUpdated(adapter)
    }
    fun addData(pos: Int, dataList: ArrayList<T>){
    fun addData(pos: Int, dataList: List<T>){
        val resultList = convertToSection(dataList)
        addSection(resultList)
        adapter?.addData(pos, resultList)
@@ -197,10 +199,10 @@
    fun getSectionLayoutId(): Int
    //自定义是否需要添加列表分组
    fun addSection(dataList: ArrayList<MySection<T>>) = Unit
    fun addSection(dataList: MutableList<MySection<T>>) = Unit
    //将数据转换为列表能接受的固定结构
    fun convertToSection(list: ArrayList<T>): ArrayList<MySection<T>> = MySection.convert2Section(list)
    fun convertToSection(list: List<T>): MutableList<MySection<T>> = MySection.convert2Section(list)
    //数据更新结束
    fun onDataUpdated(adapter: BaseRecyclerAdapter<T>?, pos: Int? = null) = Unit
@@ -260,6 +262,9 @@
    //获取空布局
    fun getMyLoadFailView(): View? = null
    //获取加载布局
    fun getLoadMoreView(): LoadMoreView? = null
    //分割线
    fun getDivider(): RecyclerView.ItemDecoration? = null