aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt50
1 files changed, 48 insertions, 2 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
index ec012ed5..f384d134 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt
@@ -18,6 +18,7 @@ package com.pitchedapps.frost.views
import android.animation.ValueAnimator
import android.annotation.SuppressLint
+import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
@@ -29,6 +30,7 @@ import ca.allanwang.kau.utils.launchMain
import com.pitchedapps.frost.contracts.FrostContentContainer
import com.pitchedapps.frost.contracts.FrostContentCore
import com.pitchedapps.frost.contracts.FrostContentParent
+import com.pitchedapps.frost.contracts.WebFileChooser
import com.pitchedapps.frost.db.CookieDao
import com.pitchedapps.frost.db.currentCookie
import com.pitchedapps.frost.facebook.FB_HOME_URL
@@ -43,8 +45,15 @@ import com.pitchedapps.frost.web.FrostChromeClient
import com.pitchedapps.frost.web.FrostJSI
import com.pitchedapps.frost.web.FrostWebViewClient
import com.pitchedapps.frost.web.NestedWebView
+import dagger.BindsInstance
+import dagger.hilt.DefineComponent
+import dagger.hilt.EntryPoint
+import dagger.hilt.EntryPoints
+import dagger.hilt.InstallIn
import dagger.hilt.android.AndroidEntryPoint
+import dagger.hilt.android.components.ViewComponent
import javax.inject.Inject
+import javax.inject.Scope
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
@@ -61,6 +70,9 @@ class FrostWebView @JvmOverloads constructor(
) : NestedWebView(context, attrs, defStyleAttr), FrostContentCore {
@Inject
+ lateinit var activity: Activity
+
+ @Inject
lateinit var fbCookie: FbCookie
@Inject
@@ -70,8 +82,14 @@ class FrostWebView @JvmOverloads constructor(
lateinit var themeProvider: ThemeProvider
@Inject
+ lateinit var webFileChooser: WebFileChooser
+
+ @Inject
lateinit var cookieDao: CookieDao
+ @Inject
+ lateinit var frostWebComponentBuilder: FrostWebComponentBuilder
+
override fun reload(animate: Boolean) {
if (parent.registerTransition(false, animate))
super.reload()
@@ -86,6 +104,8 @@ class FrostWebView @JvmOverloads constructor(
@SuppressLint("SetJavaScriptEnabled")
override fun bind(container: FrostContentContainer): View {
+ val component = frostWebComponentBuilder.frostWebView(this).build()
+ val entryPoint = EntryPoints.get(component, FrostWebEntryPoint::class.java)
userAgentString = USER_AGENT
with(settings) {
javaScriptEnabled = true
@@ -98,8 +118,8 @@ class FrostWebView @JvmOverloads constructor(
// attempt to get custom client; otherwise fallback to original
frostWebClient = (container as? WebFragment)?.client(this) ?: FrostWebViewClient(this)
webViewClient = frostWebClient
- webChromeClient = FrostChromeClient(this, themeProvider)
- addJavascriptInterface(FrostJSI(this), "Frost")
+ webChromeClient = FrostChromeClient(this, themeProvider, webFileChooser)
+ addJavascriptInterface(entryPoint.frostJsi(), "Frost")
setBackgroundColor(Color.TRANSPARENT)
setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
context.ctxCoroutine.launchMain {
@@ -231,3 +251,29 @@ class FrostWebView @JvmOverloads constructor(
super.destroy()
}
}
+
+@Scope
+@Retention(AnnotationRetention.BINARY)
+@Target(
+ AnnotationTarget.FUNCTION,
+ AnnotationTarget.TYPE,
+ AnnotationTarget.CLASS
+)
+annotation class FrostWebScoped
+
+@FrostWebScoped
+@DefineComponent(parent = ViewComponent::class)
+interface FrostWebComponent
+
+@DefineComponent.Builder
+interface FrostWebComponentBuilder {
+ fun frostWebView(@BindsInstance web: FrostWebView): FrostWebComponentBuilder
+ fun build(): FrostWebComponent
+}
+
+@EntryPoint
+@InstallIn(FrostWebComponent::class)
+interface FrostWebEntryPoint {
+ @FrostWebScoped
+ fun frostJsi(): FrostJSI
+}