diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-15 19:25:17 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-15 19:25:17 -0700 |
commit | c8f76b5aa406f84f49789a50871c68a1a95a232d (patch) | |
tree | 7a47029f13dd023b2947eb294c8c9f7c7dbd3fe0 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt | |
parent | 0d1f0e215b1890f2f5d45373b2746b7ef91da494 (diff) | |
download | frost-c8f76b5aa406f84f49789a50871c68a1a95a232d.tar.gz frost-c8f76b5aa406f84f49789a50871c68a1a95a232d.tar.bz2 frost-c8f76b5aa406f84f49789a50871c68a1a95a232d.zip |
Only animate webview when explicitly asked
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt | 40 |
1 files changed, 35 insertions, 5 deletions
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 db5f877d..86d88e47 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewCore.kt @@ -12,8 +12,13 @@ import android.view.MotionEvent import android.view.View import android.view.animation.DecelerateInterpolator import android.webkit.WebView +import ca.allanwang.kau.utils.circularReveal +import ca.allanwang.kau.utils.fadeIn +import ca.allanwang.kau.utils.fadeOut +import ca.allanwang.kau.utils.isVisible import com.pitchedapps.frost.facebook.FbTab import com.pitchedapps.frost.facebook.USER_AGENT_BASIC +import com.pitchedapps.frost.utils.L import io.reactivex.Scheduler import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable @@ -65,13 +70,38 @@ class FrostWebViewCore @JvmOverloads constructor( setBackgroundColor(Color.TRANSPARENT) } - override fun loadUrl(url: String?) { - if (url != null) - super.loadUrl(url) + fun loadUrl(url: String?, animate: Boolean) { + if (url == null) return + registerTransition(animate) + super.loadUrl(url) } - fun loadBaseUrl() { - loadUrl(baseUrl) + fun reload(animate: Boolean) { + registerTransition(animate) + super.reload() + } + + /** + * Hook onto the refresh observable for one cycle + * Note that this is a behaviour subject so the first 'false' emission should be ignored + */ + fun registerTransition(animate: Boolean) { + var dispose: Disposable? = null + var loading = false + dispose = refreshObservable.subscribeOn(AndroidSchedulers.mainThread()).subscribe { + if (it) { + loading = true + if (isVisible()) fadeOut(duration = 200L) + } else if (loading) { + dispose?.dispose() + if (animate) circularReveal(offset = 150L) + else fadeIn(duration = 100L) + } + } + } + + fun loadBaseUrl(animate: Boolean = true) { + loadUrl(baseUrl, animate) } fun addTitleListener(subscriber: (title: String) -> Unit, scheduler: Scheduler = AndroidSchedulers.mainThread()): Disposable |