summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-17 17:07:43 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-01 19:53:26 +0000
commitfef9833c1c6df24d245b67f84a6048c97c688029 (patch)
tree12453f2f1e8b3eeeec10e58948f90cafa34f3964
parent5069f501441c602c448af482a00c9e7f3b86318f (diff)
downloadmullvadvpn-fef9833c1c6df24d245b67f84a6048c97c688029.tar.xz
mullvadvpn-fef9833c1c6df24d245b67f84a6048c97c688029.zip
Create `CustomRecyclerView` to listen to scrolling
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/CustomRecyclerView.kt38
1 files changed, 38 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/CustomRecyclerView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/CustomRecyclerView.kt
new file mode 100644
index 0000000000..710bb834d0
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/CustomRecyclerView.kt
@@ -0,0 +1,38 @@
+package net.mullvad.mullvadvpn.ui.widget
+
+import android.content.Context
+import android.support.v7.widget.RecyclerView
+import android.util.AttributeSet
+import net.mullvad.mullvadvpn.util.ListenableScrollableView
+
+class CustomRecyclerView : RecyclerView, ListenableScrollableView {
+ override var horizontalScrollOffset = 0
+ override var verticalScrollOffset = 0
+
+ override var onScrollListener: ((Int, Int, Int, Int) -> Unit)? = null
+
+ constructor(context: Context) : super(context) {}
+
+ constructor(context: Context, attributes: AttributeSet) : super(context, attributes) {}
+
+ constructor(context: Context, attributes: AttributeSet, defaultStyleAttribute: Int) :
+ super(context, attributes, defaultStyleAttribute) {
+ }
+
+ override fun onScrolled(horizontalDelta: Int, verticalDelta: Int) {
+ super.onScrolled(horizontalDelta, verticalDelta)
+
+ val oldHorizontalScrollOffset = horizontalScrollOffset
+ val oldVerticalScrollOffset = verticalScrollOffset
+
+ horizontalScrollOffset += horizontalDelta
+ verticalScrollOffset += verticalDelta
+
+ onScrollListener?.invoke(
+ horizontalScrollOffset,
+ verticalScrollOffset,
+ oldHorizontalScrollOffset,
+ oldVerticalScrollOffset
+ )
+ }
+}