diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
5 files changed, 51 insertions, 36 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt index 3ab954c6..8d4deef8 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt @@ -34,6 +34,8 @@ import com.pitchedapps.frost.utils.isFacebookUrl import java.io.File import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import org.koin.core.KoinComponent +import org.koin.core.inject /** * Created by Allan Wang on 2018-01-05. @@ -44,8 +46,9 @@ class DebugWebView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : WebView(context, attrs, defStyleAttr) { +) : WebView(context, attrs, defStyleAttr), KoinComponent { + private val prefs: Prefs by inject() var onPageFinished: (String?) -> Unit = {} init { @@ -93,7 +96,7 @@ class DebugWebView @JvmOverloads constructor( private fun injectBackgroundColor() { setBackgroundColor( - if (url.isFacebookUrl) Prefs.bgColor.withAlpha(255) + if (url.isFacebookUrl) prefs.bgColor.withAlpha(255) else Color.WHITE ) } @@ -104,15 +107,16 @@ class DebugWebView @JvmOverloads constructor( if (url.isFacebookUrl) view.jsInject( // CssHider.CORE, - CssHider.COMPOSER.maybe(!Prefs.showComposer), - CssHider.STORIES.maybe(!Prefs.showStories), - CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends), - CssHider.SUGGESTED_GROUPS.maybe(!Prefs.showSuggestedGroups), - Prefs.themeInjector, + CssHider.COMPOSER.maybe(!prefs.showComposer), + CssHider.STORIES.maybe(!prefs.showStories), + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), + CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), + prefs.themeInjector, CssHider.NON_RECENT.maybe( (url?.contains("?sk=h_chr") ?: false) && - Prefs.aggressiveRecents - ) + prefs.aggressiveRecents + ), + prefs = prefs ) } } 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 c8e551a3..05248153 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -41,6 +41,8 @@ import kotlinx.coroutines.launch */ class FrostJSI(val web: FrostWebView) { + private val fbCookie: FbCookie get() = web.fbCookie + private val prefs: Prefs get() = web.prefs private val context: Context = web.context private val activity: MainActivity? = context as? MainActivity private val header: SendChannel<String>? = activity?.headerBadgeChannel @@ -57,7 +59,7 @@ class FrostJSI(val web: FrostWebView) { @JavascriptInterface fun loadVideo(url: String?, isGif: Boolean): Boolean = - if (url != null && Prefs.enablePip) { + if (url != null && prefs.enablePip) { web.post { (context as? VideoViewHolder)?.showVideo(url, isGif) ?: L.e { "Could not load video; contract not implemented" } @@ -79,7 +81,7 @@ class FrostJSI(val web: FrostWebView) { @JavascriptInterface fun contextMenu(url: String?, text: String?) { // url will be formatted through webcontext - web.post { context.showWebContextMenu(WebContext(url.takeIf { it.isIndependent }, text)) } + web.post { context.showWebContextMenu(WebContext(url.takeIf { it.isIndependent }, text), fbCookie) } } /** @@ -113,7 +115,7 @@ class FrostJSI(val web: FrostWebView) { fun loadLogin() { L.d { "Sign up button found; load login" } context.ctxCoroutine.launch { - FbCookie.logout(context) + fbCookie.logout(context) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt index 9e5e6c63..b4dd93da 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -20,12 +20,10 @@ import ca.allanwang.kau.utils.runOnUiThread import com.pitchedapps.frost.activities.WebOverlayActivity import com.pitchedapps.frost.activities.WebOverlayActivityBase import com.pitchedapps.frost.contracts.VideoViewHolder -import com.pitchedapps.frost.facebook.FbCookie import com.pitchedapps.frost.facebook.FbItem import com.pitchedapps.frost.facebook.USER_AGENT_DESKTOP_CONST import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.isFacebookUrl import com.pitchedapps.frost.utils.isImageUrl import com.pitchedapps.frost.utils.isIndependent @@ -69,32 +67,32 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { } if (url.isIndirectImageUrl) { L.d { "Found indirect fb image" } - context.launchImageActivity(url, cookie = FbCookie.webCookie) + context.launchImageActivity(url, cookie = fbCookie.webCookie) return true } if (!url.isIndependent) { L.d { "Forbid overlay switch" } return false } - if (!Prefs.overlayEnabled) return false + if (!prefs.overlayEnabled) return false if (context is WebOverlayActivityBase) { val shouldUseDesktop = url.isFacebookUrl // already overlay; manage user agent if (userAgentString != USER_AGENT_DESKTOP_CONST && shouldUseDesktop) { L._i { "Switch to desktop agent overlay" } - context.launchWebOverlayDesktop(url) + context.launchWebOverlayDesktop(url, fbCookie) return true } if (userAgentString == USER_AGENT_DESKTOP_CONST && !shouldUseDesktop) { L._i { "Switch from desktop agent" } - context.launchWebOverlayMobile(url) + context.launchWebOverlayMobile(url, fbCookie) return true } L._i { "return false switch" } return false } L.v { "Request web overlay passed" } - context.launchWebOverlay(url) + context.launchWebOverlay(url, fbCookie) return true } 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 2cd4c5db..a3c61323 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -67,6 +67,8 @@ open class BaseWebViewClient : WebViewClient() { */ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { + private val fbCookie: FbCookie get() = web.fbCookie + private val prefs: Prefs get() = web.prefs private val refresh: SendChannel<Boolean> = web.parent.refreshChannel private val isMain = web.parent.baseEnum != null /** @@ -102,7 +104,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { web.setBackgroundColor( when { isMain -> Color.TRANSPARENT - web.url.isFacebookUrl -> Prefs.bgColor.withAlpha(255) + web.url.isFacebookUrl -> prefs.bgColor.withAlpha(255) else -> Color.WHITE } ) @@ -115,21 +117,22 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { view.jsInject( // CssHider.CORE, CssHider.HEADER, - CssHider.COMPOSER.maybe(!Prefs.showComposer), - CssHider.STORIES.maybe(!Prefs.showStories), - CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends), - CssHider.SUGGESTED_GROUPS.maybe(!Prefs.showSuggestedGroups), - Prefs.themeInjector, + CssHider.COMPOSER.maybe(!prefs.showComposer), + CssHider.STORIES.maybe(!prefs.showStories), + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), + CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), + prefs.themeInjector, CssHider.NON_RECENT.maybe( (web.url?.contains("?sk=h_chr") ?: false) && - Prefs.aggressiveRecents + prefs.aggressiveRecents ), JsAssets.DOCUMENT_WATCHER, JsAssets.HORIZONTAL_SCROLLING, JsAssets.CLICK_A, - CssHider.ADS.maybe(!Prefs.showFacebookAds), + CssHider.ADS.maybe(!prefs.showFacebookAds), JsAssets.CONTEXT_A, - JsAssets.MEDIA + JsAssets.MEDIA, + prefs = prefs ) } else { refresh.offer(false) @@ -147,7 +150,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { } internal open fun onPageFinishedActions(url: String) { - if (url.startsWith("${FbItem.MESSAGES.url}/read/") && Prefs.messageScrollToBottom) { + if (url.startsWith("${FbItem.MESSAGES.url}/read/") && prefs.messageScrollToBottom) { web.pageDown(true) } injectAndFinish() @@ -160,7 +163,8 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { web.jsInject( JsActions.LOGIN_CHECK, JsAssets.TEXTAREA_LISTENER, - JsAssets.HEADER_BADGES.maybe(isMain) + JsAssets.HEADER_BADGES.maybe(isMain), + prefs = prefs ) } @@ -202,12 +206,12 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { return launchRequest(request) } if (url.isIndirectImageUrl) { - return launchImage(url.formattedFbUrl, cookie = FbCookie.webCookie) + return launchImage(url.formattedFbUrl, cookie = fbCookie.webCookie) } if (url.isImageUrl) { return launchImage(url.formattedFbUrl) } - if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) { + if (prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) { return true } // Convert desktop urls to mobile ones @@ -229,12 +233,14 @@ private const val EMIT_FINISH = 0 */ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { + private val prefs: Prefs get() = web.prefs + override fun onPageFinished(view: WebView, url: String?) { super.onPageFinished(view, url) if (url == null) { return } - jsInject(JsAssets.MENU) + jsInject(JsAssets.MENU, prefs = prefs) } override fun emit(flag: Int) { 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 33a4875f..37e06db9 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt @@ -42,6 +42,8 @@ import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.isFacebookUrl import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.coroutineScope +import org.koin.core.KoinComponent +import org.koin.core.inject /** * Created by Allan Wang on 2017-05-29. @@ -50,8 +52,10 @@ class LoginWebView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : WebView(context, attrs, defStyleAttr) { +) : WebView(context, attrs, defStyleAttr), KoinComponent { + private val fbCookie: FbCookie by inject() + private val prefs: Prefs by inject() private val completable: CompletableDeferred<CookieEntity> = CompletableDeferred() private lateinit var progressCallback: (Int) -> Unit @@ -69,7 +73,7 @@ class LoginWebView @JvmOverloads constructor( this@LoginWebView.progressCallback = progressCallback L.d { "Begin loading login" } launchMain { - FbCookie.reset() + fbCookie.reset() setupWebview() loadUrl(FB_LOGIN_URL) } @@ -101,7 +105,8 @@ class LoginWebView @JvmOverloads constructor( if (url.isFacebookUrl) view.jsInject( CssHider.CORE, - Prefs.themeInjector + prefs.themeInjector, + prefs = prefs ) } |