aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2020-02-23 16:36:31 -0800
committerAllan Wang <me@allanwang.ca>2020-02-23 16:36:31 -0800
commit0dfc1b3e6542b9deca6c56236b46e71e4c6976f5 (patch)
treed16e4c34b86b0cc236fce32baa38d71f3b7adfbf /app/src/main/kotlin/com/pitchedapps/frost/web
parentcd69ccf7c49f486a6c90a7cee0d32a74ea00247d (diff)
downloadfrost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.tar.gz
frost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.tar.bz2
frost-0dfc1b3e6542b9deca6c56236b46e71e4c6976f5.zip
Remove singleton pattern for fbcookie
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt10
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt3
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt3
4 files changed, 15 insertions, 9 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 449f0ab0..9fe4c4c9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -35,13 +35,17 @@ import com.pitchedapps.frost.utils.showWebContextMenu
import com.pitchedapps.frost.views.FrostWebView
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.launch
+import org.koin.android.ext.android.inject
+import org.koin.core.KoinComponent
+import org.koin.core.inject
/**
* Created by Allan Wang on 2017-06-01.
*/
class FrostJSI(val web: FrostWebView) {
- private val prefs: Prefs = web.prefs
+ 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
@@ -80,7 +84,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) }
}
/**
@@ -114,7 +118,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 d33b51f6..c54f9822 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -68,7 +68,7 @@ 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) {
@@ -81,19 +81,19 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean {
// 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 a931b2ed..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,7 @@ 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
@@ -205,7 +206,7 @@ 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)
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 0299ea77..37e06db9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -54,6 +54,7 @@ class LoginWebView @JvmOverloads constructor(
defStyleAttr: Int = 0
) : 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
@@ -72,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)
}