Skip to content

Commit c6364fa

Browse files
Merge pull request #26 from SimformSolutionsPvtLtd/develop
Develop to Main LGTM.
2 parents 8f0eee3 + 5806f3f commit c6364fa

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

sspulltorefresh/src/main/java/com/simform/refresh/SSPullToRefreshLayout.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,8 @@ class SSPullToRefreshLayout(context: Context?, attrs: AttributeSet? = null) :
208208
}
209209
refreshView.visibility = GONE
210210
addView(refreshView, mRefreshLayoutParams)
211-
when(refreshView) {
212-
is SSAnimationView -> { }
213-
is SSLottieAnimationView -> {
214-
refreshView.setAnimation(mLottieAnimationAssetFileName)
215-
}
216-
else -> {
217-
throw ClassCastException("Need SSLottieAnimationView or SSGifAnimationView as RefreshView")
218-
}
219-
}
211+
if (refreshView !is RefreshCallbacks) throw ClassCastException("RefreshView must implement RefreshCallbacks")
212+
if (refreshView is SSLottieAnimationView) refreshView.setAnimation(mLottieAnimationAssetFileName)
220213
mRefreshView = refreshView
221214
}
222215

@@ -685,7 +678,7 @@ class SSPullToRefreshLayout(context: Context?, attrs: AttributeSet? = null) :
685678
else -> {
686679
}
687680
}
688-
return mIsBeingDragged
681+
return if (mRefreshView.hasPoint(ev.rawX.toInt(), ev.rawY.toInt())) false else mIsBeingDragged
689682
}
690683

691684
override fun onTouchEvent(ev: MotionEvent): Boolean {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.simform.refresh
2+
3+
import android.view.View
4+
5+
/**
6+
* Defines the coordinates of the view in its window
7+
*
8+
* @return Pair of [Int] representing x and y
9+
*/
10+
val View.windowCoordinates: Pair<Int, Int>
11+
get() {
12+
val location = IntArray(2)
13+
getLocationInWindow(location)
14+
val x = location[0]
15+
val y = location[1]
16+
return x to y
17+
}
18+
19+
/**
20+
* Check if view bounds include the given point in window
21+
*
22+
* @param x The x coordinate of the point
23+
* @param y The y coordinate of the point
24+
*
25+
* @return True if the view contains given point, false otherwise
26+
*/
27+
fun View.hasPoint(x: Int, y: Int): Boolean {
28+
val viewCoordinates = windowCoordinates
29+
return x in viewCoordinates.first..(viewCoordinates.first + width) &&
30+
y in viewCoordinates.second..(viewCoordinates.second + height)
31+
}

0 commit comments

Comments
 (0)