package com.develop.food.base.widgets

import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.RecyclerView

class RecyclerViewEx : RecyclerView {
    interface OnScrollStateChangedListener {
        fun onScrollStateChanged(state: Int)
    }

    private val listeners = ArrayList<OnScrollStateChangedListener>()

    constructor(context: Context?) : super(context!!) {}
    constructor(context: Context?, attrs: AttributeSet?) : super(
        context!!, attrs
    ) {
    }

    constructor(
        context: Context?, attrs: AttributeSet?,
        defStyle: Int
    ) : super(context!!, attrs, defStyle) {
    }

    fun addOnScrollStateChangedListener(listener: OnScrollStateChangedListener) {
        listeners.add(listener)
    }

    fun removeOnScrollStateChangedListener(listener: OnScrollStateChangedListener) {
        listeners.remove(listener)
    }

    override fun onScrollStateChanged(state: Int) {
        super.onScrollStateChanged(state)
        for (listener in listeners) {
            listener.onScrollStateChanged(state)
        }
    }
}