summaryrefslogtreecommitdiffhomepage
path: root/android/src/main
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-06-16 21:10:10 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-07-01 19:12:29 +0000
commit29fb4cd8b4df834b888a79eaf4ca9d2af9e26323 (patch)
tree9d23a3909b79b12023b4cf638278734391eca5fd /android/src/main
parent40ab283b2bd438612adc919947ba9f2378f4ab8d (diff)
downloadmullvadvpn-29fb4cd8b4df834b888a79eaf4ca9d2af9e26323.tar.xz
mullvadvpn-29fb4cd8b4df834b888a79eaf4ca9d2af9e26323.zip
Allow other view types to be used as scroll area
Diffstat (limited to 'android/src/main')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt20
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ListenableScrollView.kt10
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/util/ListenableScrollableView.kt8
3 files changed, 28 insertions, 10 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt
index ec5a4549b1..df6bf504ee 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/CollapsibleTitleController.kt
@@ -5,13 +5,13 @@ import android.view.View.OnLayoutChangeListener
import android.view.ViewGroup.MarginLayoutParams
import kotlin.properties.Delegates.observable
import net.mullvad.mullvadvpn.R
-import net.mullvad.mullvadvpn.ui.widget.ListenableScrollView
import net.mullvad.mullvadvpn.util.LinearInterpolation
+import net.mullvad.mullvadvpn.util.ListenableScrollableView
// In order to use this view controller, the parent view must contain four views with specific IDs:
//
-// 1. A `ListenableScrollView` with the ID `scroll_area`, which is used to animate the title based
-// on the scroll offset.
+// 1. A `View` with the ID `scroll_area` and that implements `ListenableScrollableView`, which is
+// used to animate the title based on the scroll offset.
// 2. A view inside the `scroll_area` with the ID `expanded_title`. This view is made invisible so
// that it's not drawn, but it is used to measure the layout and the animation positions.
// 3. A view outside the `scroll_area` with the ID `collapsed_title`. This view is also made
@@ -104,16 +104,20 @@ class CollapsibleTitleController(val parentView: View) {
}
private val scrollAreaLayoutListener: LayoutListener = LayoutListener() {
- scrollOffset = scrollArea.scrollY.toFloat()
+ scrollOffset = scrollArea.verticalScrollOffset.toFloat()
}
- private val scrollArea = parentView.findViewById<ListenableScrollView>(R.id.scroll_area).apply {
- onScrollListener = { _, top, _, _ ->
+ private val scrollArea = parentView.findViewById<View>(R.id.scroll_area).let { view ->
+ val scrollableView = view as ListenableScrollableView
+
+ view.addOnLayoutChangeListener(scrollAreaLayoutListener)
+
+ scrollableView.onScrollListener = { _, top, _, _ ->
scrollOffset = top.toFloat()
update()
}
- addOnLayoutChangeListener(scrollAreaLayoutListener)
+ scrollableView
}
private var scrollOffsetUpdated = false
@@ -146,7 +150,7 @@ class CollapsibleTitleController(val parentView: View) {
fun onDestroy() {
scrollArea.onScrollListener = null
- scrollArea.removeOnLayoutChangeListener(scrollAreaLayoutListener)
+ (scrollArea as View).removeOnLayoutChangeListener(scrollAreaLayoutListener)
collapsedTitle.removeOnLayoutChangeListener(collapsedTitleLayoutListener)
expandedTitle.removeOnLayoutChangeListener(expandedTitleLayoutListener)
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ListenableScrollView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ListenableScrollView.kt
index 303527c3d4..b436df903a 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ListenableScrollView.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/ListenableScrollView.kt
@@ -3,9 +3,15 @@ package net.mullvad.mullvadvpn.ui.widget
import android.content.Context
import android.util.AttributeSet
import android.widget.ScrollView
+import net.mullvad.mullvadvpn.util.ListenableScrollableView
-class ListenableScrollView : ScrollView {
- var onScrollListener: ((Int, Int, Int, Int) -> Unit)? = null
+class ListenableScrollView : ScrollView, ListenableScrollableView {
+ override val horizontalScrollOffset
+ get() = scrollX
+ override val verticalScrollOffset
+ get() = scrollY
+
+ override var onScrollListener: ((Int, Int, Int, Int) -> Unit)? = null
constructor(context: Context) : super(context) {}
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/util/ListenableScrollableView.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/ListenableScrollableView.kt
new file mode 100644
index 0000000000..61deecacb2
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/util/ListenableScrollableView.kt
@@ -0,0 +1,8 @@
+package net.mullvad.mullvadvpn.util
+
+interface ListenableScrollableView {
+ val horizontalScrollOffset: Int
+ val verticalScrollOffset: Int
+
+ var onScrollListener: ((Int, Int, Int, Int) -> Unit)?
+}