diff options
author | Allan Wang <me@allanwang.ca> | 2017-08-14 20:48:39 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-14 20:48:39 -0700 |
commit | 5d9a3fd7fb8f2f9d0f592c89446824980c9841c6 (patch) | |
tree | a770b2564b67280fcc9fcc65144bd0b8bd8e2881 /app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | |
parent | ab7ec131b62ac1567e983c846c921bd3ada11dd4 (diff) | |
download | frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.tar.gz frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.tar.bz2 frost-5d9a3fd7fb8f2f9d0f592c89446824980c9841c6.zip |
v1.4.5 (#174)v1.4.5
* Update/kau (#125)
* Update logger
* Clean imports and bring back reactive libs
* Update dependencies and make billing async
* Misc (#128)
* Update null
* Attempt to improve transparent theme backgrounds
* Update menu
* Move injections to visible method and reduce offset
* Update searchview and logging
* Clean temp strings and add network states
* Move console blacklist to web state
* Change some logs to info
* Move glide loader to onCreate (#135)
* Remove commit number increments (#139)
* Fix/misc (#140)
* Add canadian locale to toLowerCase
* Add try catch to JsAssets
* Disable error throwing for bad search subject
* Log more throwables quietly
* Check internet connection before fetching username
* Remove name check in frost notifications
* Add activity lifecycle logger
* Add rxjava to lib showcase
* Move network checker to io thread (#150)
* Update dependency
* Blank
* Feature/jsoup debugger (#152)
* Create debugger
* Update debugger content
* Create debugging logic
* Finalize and test debugger
* Add reload listener
* Fix/pro crash without play store (#155)
* Update changelog
* Check if iab service exists
* Add checker before launching play store request
* Separate strings
* Enhancement/message notifications (#157)
* Map message notifs to the headless html extractor
* Update strings
* Bring im notifs out of alpha
* Update changelog
* Remove confirmation dialog (#159)
* Separate message notifications and add click intents (#171)
* Separate message notifications and add click intent for group notifications
* Add comments and finalize
* Feature/scroll down on message thread (#172)
* Add hook for scroll
* Update changelog
* Add custom navdrawer layout (#173)
* Add faq for auto play
* Update changelog
* Fix page banner bg (#163)
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | 82 |
1 files changed, 47 insertions, 35 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index 94bff3c3..5f679c65 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -1,8 +1,8 @@ package com.pitchedapps.frost.web import android.content.Context -import android.content.Intent import android.graphics.Bitmap +import android.graphics.Color import android.webkit.WebResourceRequest import android.webkit.WebResourceResponse import android.webkit.WebView @@ -14,10 +14,12 @@ import com.pitchedapps.frost.activities.WebOverlayActivity import com.pitchedapps.frost.facebook.FACEBOOK_COM import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.FbCookie +import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.injectors.* import com.pitchedapps.frost.utils.* import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import io.reactivex.subjects.Subject +import org.jetbrains.anko.withAlpha /** * Created by Allan Wang on 2017-05-31. @@ -42,18 +44,19 @@ open class BaseWebViewClient : WebViewClient() { open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient() { val refreshObservable: Subject<Boolean> = webCore.refreshObservable + val isMain = webCore.baseEnum != null override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) if (url == null) return - L.i("FWV Loading $url") -// L.v("Cookies ${CookieManager.getInstance().getCookie(url)}") + L.i("FWV Loading", url) refreshObservable.onNext(true) 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) }) } + fun launchLogin(c: Context) { if (c is MainActivity && c.cookies().isNotEmpty()) c.launchNewTask(SelectorActivity::class.java, c.cookies()) @@ -61,44 +64,52 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient c.launchNewTask(LoginActivity::class.java) } + fun injectBackgroundColor() + = webCore.setBackgroundColor(if (isMain) Color.TRANSPARENT else Prefs.bgColor.withAlpha(255)) + + + override fun onPageCommitVisible(view: WebView, url: String?) { + super.onPageCommitVisible(view, url) + injectBackgroundColor() + view.jsInject( + CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons), + CssHider.HEADER, + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO), + Prefs.themeInjector, + CssHider.NON_RECENT.maybe(webCore.url?.contains("?sk=h_chr") ?: false)) + } + override fun onPageFinished(view: WebView, url: String?) { - super.onPageFinished(view, url) - if (url == null) return - L.i("Page finished $url") + url ?: return + L.i("Page finished", url) if (!url.contains(FACEBOOK_COM)) { refreshObservable.onNext(false) return } - view.jsInject( - CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons), - CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends && IS_FROST_PRO), - CssHider.ADS.maybe(!Prefs.showFacebookAds && IS_FROST_PRO) - ) onPageFinishedActions(url) } open internal fun onPageFinishedActions(url: String) { + if (url.startsWith("${FbItem.MESSAGES.url}/read/") && Prefs.messageScrollToBottom) + webCore.pageDown(true) injectAndFinish() } internal fun injectAndFinish() { L.d("Page finished reveal") - webCore.jsInject(CssHider.HEADER, - CssHider.NON_RECENT.maybe(webCore.url.contains("?sk=h_chr")), - Prefs.themeInjector, - callback = { - refreshObservable.onNext(false) - webCore.jsInject( - JsActions.LOGIN_CHECK, - JsAssets.CLICK_A.maybe(webCore.baseEnum != null && Prefs.overlayEnabled), - JsAssets.TEXTAREA_LISTENER, - JsAssets.CONTEXT_A, - JsAssets.HEADER_BADGES.maybe(webCore.baseEnum != null) - ) - }) - } - - open fun handleHtml(html: String) { + refreshObservable.onNext(false) + injectBackgroundColor() + webCore.jsInject( + JsActions.LOGIN_CHECK, + JsAssets.CLICK_A.maybe(webCore.baseEnum != null && Prefs.overlayEnabled), + JsAssets.TEXTAREA_LISTENER, + CssHider.ADS.maybe(!Prefs.showFacebookAds && IS_FROST_PRO), + JsAssets.CONTEXT_A, + JsAssets.HEADER_BADGES.maybe(webCore.baseEnum != null) + ) + } + + open fun handleHtml(html: String?) { L.d("Handle Html") } @@ -112,26 +123,26 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : BaseWebViewClient * returns false if we are already in an overlaying activity */ private fun launchRequest(request: WebResourceRequest): Boolean { - L.d("Launching Url", request.url.toString()) + L.d("Launching Url", request.url?.toString() ?: "null") if (webCore.context is WebOverlayActivity) return false webCore.context.launchWebOverlay(request.url.toString()) return true } - private fun launchImage(request: WebResourceRequest, text: String? = null): Boolean { - L.d("Launching Image", request.url.toString()) - webCore.context.launchImageActivity(request.url.toString(), text) + private fun launchImage(url: String, text: String? = null): Boolean { + L.d("Launching Image", url) + webCore.context.launchImageActivity(url, text) if (webCore.canGoBack()) webCore.goBack() return true } override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean { - L.i("Url Loading ${request.url}") - val path = request.url.path ?: return super.shouldOverrideUrlLoading(view, request) - L.v("Url Loading Path $path") + L.i("Url Loading", request.url?.toString()) + val path = request.url?.path ?: return super.shouldOverrideUrlLoading(view, request) + L.v("Url Loading Path", path) if (path.startsWith("/composer/")) return launchRequest(request) if (request.url.toString().contains("scontent-sea1-1.xx.fbcdn.net") && (path.endsWith(".jpg") || path.endsWith(".png"))) - return launchImage(request) + return launchImage(request.url.toString()) if (view.context.resolveActivityForUri(request.url)) return true return super.shouldOverrideUrlLoading(view, request) } @@ -163,6 +174,7 @@ class FrostWebViewClientMenu(webCore: FrostWebViewCore) : FrostWebViewClient(web } override fun onPageFinishedActions(url: String) { + L.d("Should inject ${url.shouldInjectMenu}") if (!url.shouldInjectMenu) injectAndFinish() } } |