package xn.hxp.weidith

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

class SwipeViewPager @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null
) :
    ViewPager(context, attrs) {

    private var swipeEnabled: Boolean = false

    fun setSwipeEnabled(enabled: Boolean) {
        this.swipeEnabled = enabled
    }

    override fun onTouchEvent(ev: MotionEvent?): Boolean {
        return swipeEnabled && super.onTouchEvent(ev)
    }

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        return swipeEnabled && super.onInterceptTouchEvent(ev)
    }
}