2022-03-18 18:33:54 +05:30
|
|
|
package com.github.libretube
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.MotionEvent
|
|
|
|
import android.view.MotionEvent.ACTION_MOVE
|
|
|
|
import android.view.ViewConfiguration
|
|
|
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|
|
|
|
2022-03-18 20:43:07 +05:30
|
|
|
class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
|
|
|
|
SwipeRefreshLayout(context!!, attrs) {
|
|
|
|
private val mTouchSlop: Int
|
|
|
|
private var mPrevX = 0f
|
2022-03-18 18:33:54 +05:30
|
|
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
|
|
|
when (event.action) {
|
2022-03-18 20:43:07 +05:30
|
|
|
MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x
|
2022-03-18 18:33:54 +05:30
|
|
|
ACTION_MOVE -> {
|
2022-03-18 20:43:07 +05:30
|
|
|
val eventX = event.x
|
|
|
|
val xDiff = Math.abs(eventX - mPrevX)
|
|
|
|
if (xDiff > mTouchSlop) {
|
2022-03-18 18:33:54 +05:30
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onInterceptTouchEvent(event)
|
|
|
|
}
|
|
|
|
|
2022-03-18 20:43:07 +05:30
|
|
|
init {
|
|
|
|
mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
2022-03-18 18:33:54 +05:30
|
|
|
}
|
|
|
|
}
|