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/FrostWebViewClientMenu.kt | |
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/FrostWebViewClientMenu.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClientMenu.kt | 33 |
1 files changed, 16 insertions, 17 deletions
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() |