aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web/SwipeRefreshBase.kt
blob: 0e303e491c6abbc1dde74d5406f8268069971ea8 (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
package com.pitchedapps.frost.web

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.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
//    }
}