diff options
author | Allan Wang <me@allanwang.ca> | 2017-06-16 00:53:10 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2017-06-16 00:53:10 -0700 |
commit | b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff (patch) | |
tree | 95a8519b719a37dfb791bb6771c940a11e9f7e9e /app/src/main/kotlin/com/pitchedapps/frost/web | |
parent | f84a05f8aeb73ce63f77b7cc779845c31427b2b2 (diff) | |
download | frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.gz frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.tar.bz2 frost-b9ea80d5b5a06d050ce2c7ca46ed597f4cb499ff.zip |
Add listener logic
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
3 files changed, 27 insertions, 27 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 bb482c3c..f81c6a15 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -19,8 +19,15 @@ class FrostJSI(val context: Context, val webView: FrostWebViewCore) { val cookies: ArrayList<CookieModel> get() = (context as? MainActivity)?.cookies() ?: arrayListOf() + var lastUrl: String = "" + @JavascriptInterface - fun loadUrl(url: String) = context.launchWebOverlay(url) + fun loadUrl(url: String) { + if (url != lastUrl) { + lastUrl = url + context.launchWebOverlay(url) + } + } @JavascriptInterface fun reloadBaseUrl(animate: Boolean) { 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 07b9a949..8cd36b86 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -62,7 +62,7 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { L.d("Page finished reveal") webCore.jsInject(CssHider.HEADER, Prefs.themeInjector, - JsAssets.CLICK_INTERCEPTOR, +// JsAssets.CLICK_INTERCEPTOR, callback = { L.d("Finished ${it.contentToString()}") refreshObservable.onNext(false) @@ -77,14 +77,6 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { L.d("Emit $flag") } - fun inject(jsAssets: JsAssets, view: WebView, callback: (String) -> Unit = {}) { - L.i("Post inject ${jsAssets.name}") - jsAssets.inject(view, { - L.i("Post injection done $it") - callback.invoke(it) - }) - } - override fun shouldOverrideKeyEvent(view: WebView, event: KeyEvent): Boolean { L.d("Key event ${event.keyCode}") return super.shouldOverrideKeyEvent(view, event) @@ -95,6 +87,8 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { return super.shouldOverrideUrlLoading(view, request) } + + override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest?): WebResourceResponse? { if (request == null || !(request.url.host?.contains(FACEBOOK_COM) ?: false)) return super.shouldInterceptRequest(view, request) L.v("Url intercept ${request.url.path}") 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 9a00c563..2a1a5b74 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt @@ -2,7 +2,9 @@ package com.pitchedapps.frost.web import android.graphics.Bitmap import android.webkit.WebView +import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.injectors.JsAssets +import com.pitchedapps.frost.injectors.jsInject import com.pitchedapps.frost.utils.L import io.reactivex.subjects.Subject @@ -13,17 +15,18 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web var content: String? = null val progressObservable: Subject<Int> = webCore.progressObservable + private val contentBaseUrl = "https://touch.facebook.com/notifications" override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) if (content != null) { - when (url) { - "https://m.facebook.com/settings", - "https://m.facebook.com/settings#", - "https://m.facebook.com/settings#!/settings?soft=bookmarks" -> { + when (url.removePrefix(FB_URL_BASE)) { + "settings", + "settings#", + "settings#!/settings?soft=bookmarks" -> { L.d("Load from stored $url") view.stopLoading() - view.loadDataWithBaseURL("https://touch.facebook.com/notifications", content, "text/html", "utf-8", "https://google.ca/test") + view.loadDataWithBaseURL(contentBaseUrl, content, "text/html", "utf-8", "https://google.ca/test") } } } @@ -31,27 +34,23 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web override fun onPageFinished(view: WebView, url: String) { super.onPageFinished(view, url) - if (url == webCore.baseUrl) { - progressObservable.onNext(99) - inject(JsAssets.MENU, webCore, { - inject(JsAssets.MENU_CLICK, webCore) //menu injection must be after or we will have a loop from the click listener + if (url == webCore.baseUrl && content == null) { + jsInject(JsAssets.MENU, callback = { + jsInject(JsAssets.MENU_CLICK) //menu injection must be after or we will have a loop from the click listener }) - } else { - inject(JsAssets.MENU_CLICK, webCore) - } + } else if (url == contentBaseUrl) jsInject(JsAssets.MENU_CLICK) } override fun emit(flag: Int) { super.emit(flag) - progressObservable.onNext(100) super.injectAndFinish() } override fun onPageFinishedActions(url: String?) { - when (url) { - "https://m.facebook.com/settings", - "https://m.facebook.com/settings#", - "https://m.facebook.com/settings#!/settings?soft=bookmarks" -> { + when (url?.removePrefix(FB_URL_BASE)) { + "settings", + "settings#", + "settings#!/settings?soft=bookmarks" -> { //do nothing; we will further inject before revealing } else -> injectAndFinish() |