mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 23:00:31 +05:30
31 lines
999 B
Kotlin
31 lines
999 B
Kotlin
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
|
|
|
|
class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
|
|
SwipeRefreshLayout(context!!, attrs) {
|
|
private val mTouchSlop: Int
|
|
private var mPrevX = 0f
|
|
override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
|
|
when (event.action) {
|
|
MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x
|
|
ACTION_MOVE -> {
|
|
val eventX = event.x
|
|
val xDiff = Math.abs(eventX - mPrevX)
|
|
if (xDiff > mTouchSlop) {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return super.onInterceptTouchEvent(event)
|
|
}
|
|
|
|
init {
|
|
mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
|
}
|
|
} |