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 | |
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')
6 files changed, 48 insertions, 26 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt index 14ea4df8..bb482c3c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -23,11 +23,11 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) { fun loadUrl(url: String) = context.launchWebOverlay(url) @JavascriptInterface - fun reloadBaseUrl() { + fun reloadBaseUrl(animate: Boolean) { L.d("FrostJSI reload") webView.post { webView.stopLoading() - webView.loadBaseUrl() + webView.loadBaseUrl(animate) } } 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 c99feaf5..a600489d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebView.kt @@ -50,8 +50,8 @@ class FrostWebView @JvmOverloads constructor(context: Context, attrs: AttributeS //Some urls have postJavascript injections so make sure we load the base url override fun onRefresh() { when (web.baseUrl) { - FbTab.MENU.url -> web.loadBaseUrl() - else -> web.reload() + FbTab.MENU.url -> web.loadBaseUrl(true) + else -> web.reload(true) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index c3eb0a1f..e4ff4e10 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -4,7 +4,6 @@ import android.content.Context import android.graphics.Bitmap import android.view.KeyEvent import android.webkit.* -import ca.allanwang.kau.utils.isVisible import com.pitchedapps.frost.LoginActivity import com.pitchedapps.frost.MainActivity import com.pitchedapps.frost.SelectorActivity @@ -18,9 +17,6 @@ import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.cookies import com.pitchedapps.frost.utils.launchNewTask -import com.pitchedapps.frost.views.circularReveal -import com.pitchedapps.frost.views.fadeIn -import com.pitchedapps.frost.views.fadeOut import io.reactivex.subjects.Subject /** @@ -36,7 +32,6 @@ open class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebView if (!url.contains(FACEBOOK_COM)) return if (url.contains("logout.php")) FbCookie.logout(Prefs.userId, { launchLogin(view.context) }) else if (url.contains("login.php")) FbCookie.reset({ launchLogin(view.context) }) - view.fadeOut(duration = 200L) } fun launchLogin(c: Context) { @@ -50,19 +45,18 @@ open class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebView super.onPageFinished(view, url) if (!url.contains(FACEBOOK_COM)) { refreshObservable.onNext(false) - if (!view.isVisible()) view.fadeIn(duration = 200L) return } L.i("Page finished $url") JsActions.LOGIN_CHECK.inject(view) - onPageFinishedReveal(view as FrostWebViewCore, url) + onPageFinishedActions(view as FrostWebViewCore, url) } - open internal fun onPageFinishedReveal(view: FrostWebViewCore, url: String?) { - onPageFinishedReveal(view, true) + open internal fun onPageFinishedActions(view: FrostWebViewCore, url: String?) { + onPageFinishedActions(view) } - internal fun onPageFinishedReveal(view: FrostWebViewCore, animate: Boolean) { + internal fun onPageFinishedActions(view: FrostWebViewCore) { L.d("Page finished reveal") view.jsInject(CssHider.HEADER, Prefs.themeInjector, @@ -70,8 +64,6 @@ open class FrostWebViewClient(val refreshObservable: Subject<Boolean>) : WebView callback = { L.d("Finished ${it.contentToString()}") refreshObservable.onNext(false) - if (animate) view.circularReveal(offset = 150L) - else view.fadeIn(duration = 100L) }) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt index 3b032f62..f299b840 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt @@ -45,18 +45,18 @@ class FrostWebViewClientMenu(refreshObservable: Subject<Boolean>) : FrostWebView override fun emit(flag: Int) { super.emit(flag) - if (view != null) super.onPageFinishedReveal(view!!, true) + if (view != null) super.onPageFinishedActions(view!!) view = null } - override fun onPageFinishedReveal(view: FrostWebViewCore, url: String?) { + override fun onPageFinishedActions(view: FrostWebViewCore, url: String?) { when (url) { "https://m.facebook.com/settings", "https://m.facebook.com/settings#", "https://m.facebook.com/settings#!/settings?soft=bookmarks" -> { //do nothing; we will further inject before revealing } - else -> super.onPageFinishedReveal(view, false) + else -> super.onPageFinishedActions(view) } } 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 diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt index aa10e602..8265f429 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -5,6 +5,8 @@ import android.content.Context import android.util.AttributeSet import android.view.View import android.webkit.* +import ca.allanwang.kau.utils.fadeIn +import ca.allanwang.kau.utils.snackbar import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FbCookie @@ -12,8 +14,6 @@ import com.pitchedapps.frost.injectors.CssHider import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs -import com.pitchedapps.frost.views.fadeIn -import com.pitchedapps.frost.views.snackbar import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.SingleSubject import io.reactivex.subjects.Subject |