aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/SwipeRefreshBase.kt
blob: 59d42722b2151401121d524b9c0dc6960f9cf7f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.pitchedapps.frost.views

import android.content.Context
import android.support.v4.widget.SwipeRefreshLayout
import android.util.AttributeSet
import android.view.MotionEvent
import android.webkit.WebView
import com.pitchedapps.frost.utils.L
import com.pitchedapps.frost.utils.Utils


/**
 * Created by Allan Wang on 2017-05-28.
 */
class SwipeRefreshBase @JvmOverloads constructor(
        context: Context?, attrs: AttributeSet? = null
) : SwipeRefreshLayout(context, attrs) {

    lateinit var shouldSwipe: (ev: MotionEvent) -> Boolean

    companion object {
        private val SCROLL_BUFFER by lazy { Utils.dpToPx(5) }
        fun shouldScroll(webview: WebView) = webview.scrollY <= SCROLL_BUFFER
    }

//    override fun onInterceptTouchEvent(ev: MotionEvent):Boolean {
//        val b = shouldSwipe.invoke(ev) && super.onInterceptTouchEvent(ev)
//        L.e("Should swipe $b")
//        return b
//    }
}