diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-12 16:51:27 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-12 16:51:27 -0700 |
commit | a17ae247c496d2ec8038f36428812f3c2e410d87 (patch) | |
tree | 310e5a4d49a08dd8dcf876cd8768ce0053ba2df0 /app/src/main/kotlin/com/pitchedapps/frost/web | |
parent | 605a08c2e2e8634263d7626cf7471310add3acb2 (diff) | |
download | frost-a17ae247c496d2ec8038f36428812f3c2e410d87.tar.gz frost-a17ae247c496d2ec8038f36428812f3c2e410d87.tar.bz2 frost-a17ae247c496d2ec8038f36428812f3c2e410d87.zip |
Add kau and web scrolling
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt | 3 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt | 23 |
2 files changed, 11 insertions, 15 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt index 439ab6fa..d4bf8e07 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -9,7 +9,7 @@ import android.widget.FrameLayout import android.widget.ProgressBar import butterknife.ButterKnife import com.pitchedapps.frost.R -import com.pitchedapps.frost.utils.bindView +import ca.allanwang.kau.utils.bindView import io.reactivex.android.schedulers.AndroidSchedulers /** @@ -28,7 +28,6 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS init { inflate(getContext(), R.layout.swipe_webview, this) - ButterKnife.bind(this) web.progressObservable.observeOn(AndroidSchedulers.mainThread()).subscribe { progress.visibility = if (it == 100) View.INVISIBLE else View.VISIBLE if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progress.setProgress(it, true) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt index 146f5a33..1d3f348a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -3,7 +3,6 @@ package com.pitchedapps.frost.web import android.animation.ValueAnimator import android.annotation.SuppressLint import android.content.Context -import android.support.v4.view.MotionEventCompat import android.support.v4.view.NestedScrollingChild import android.support.v4.view.NestedScrollingChildHelper import android.support.v4.view.ViewCompat @@ -12,9 +11,7 @@ import android.view.MotionEvent import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView -import com.pitchedapps.frost.MainActivity -import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.cookies +import com.pitchedapps.frost.facebook.USER_AGENT_BASIC import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -53,6 +50,7 @@ class FrostWebViewCore @JvmOverloads constructor( @SuppressLint("SetJavaScriptEnabled") fun setupWebview() { settings.javaScriptEnabled = true + settings.userAgentString = USER_AGENT_BASIC // settings.domStorageEnabled = true setLayerType(View.LAYER_TYPE_HARDWARE, null) setWebViewClient(FrostWebViewClient(refreshObservable)) @@ -72,7 +70,7 @@ class FrostWebViewCore @JvmOverloads constructor( override fun onTouchEvent(ev: MotionEvent): Boolean { val event = MotionEvent.obtain(ev) - val action = MotionEventCompat.getActionMasked(event) + val action = event.action if (action == MotionEvent.ACTION_DOWN) nestedOffsetY = 0 val eventY = event.y.toInt() @@ -115,21 +113,20 @@ class FrostWebViewCore @JvmOverloads constructor( * Otherwise scroll to top */ fun scrollOrRefresh() { - L.d("Scroll or Refresh") if (scrollY < 5) loadBaseUrl() else scrollToTop() } fun scrollToTop() { - if (scrollY > 1000) scrollTo(0, 0) - else { + flingScroll(0, 0) // stop fling + if (scrollY > 10000) { + scrollTo(0, 0) + } else { val animator = ValueAnimator.ofInt(scrollY, 0) - animator.duration = scrollY.toLong() + animator.duration = Math.min(scrollY, 500).toLong() animator.interpolator = DecelerateInterpolator() - animator.addUpdateListener { - scrollY = it.animatedValue as Int - invalidate() - } + animator.addUpdateListener { scrollY = it.animatedValue as Int } + animator.start() } } |