package com.remax.visualnovel.app.widget

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.chad.library.adapter.base.loadmore.BaseLoadMoreView
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.remax.visualnovel.R
import com.remax.visualnovel.extension.setSize

/**
 * Created by HJW on 2020/9/18
 */
class CustomLoadMoreView(private val showLoading: Boolean = true) : BaseLoadMoreView() {

    override fun getLoadComplete(holder: BaseViewHolder): View {
        return holder.getView(R.id.load_more_load_complete_view)
    }

    override fun getLoadEndView(holder: BaseViewHolder): View {
        return holder.getView(R.id.load_more_load_end_view)
    }

    override fun getLoadFailView(holder: BaseViewHolder): View {
        return holder.getView(R.id.load_more_load_fail_view)
    }

    override fun getLoadingView(holder: BaseViewHolder): View {
        val loadingView = holder.getView<View>(R.id.load_more_loading_view)
        if (!showLoading) {
            loadingView.setSize(height = 0)
        }
        return loadingView
    }

    override fun getRootView(parent: ViewGroup): View {
        // 整个 LoadMore 布局
        return LayoutInflater.from(parent.context).inflate(R.layout.view_load_more_common, parent, false)
    }
}