diff options
author | Allan Wang <me@allanwang.ca> | 2021-09-25 16:54:09 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2021-09-25 16:54:09 -0700 |
commit | 3b4b164f524575c9dc10955d329710ba0706c9ed (patch) | |
tree | 2ec89d4991642efa927fddc01d02e1d81aa1631f /app/src/main/kotlin/com/pitchedapps/frost/views/FrostWebView.kt | |
parent | 8be8b88247973592b2afe134f99c8102929e0b2d (diff) | |
download | frost-3b4b164f524575c9dc10955d329710ba0706c9ed.tar.gz frost-3b4b164f524575c9dc10955d329710ba0706c9ed.tar.bz2 frost-3b4b164f524575c9dc10955d329710ba0706c9ed.zip |
Create frost web component for jsi
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.kt | 44 |
1 files changed, 43 insertions, 1 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 695e1226..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 @@ -44,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 @@ -62,6 +70,9 @@ class FrostWebView @JvmOverloads constructor( ) : NestedWebView(context, attrs, defStyleAttr), FrostContentCore { @Inject + lateinit var activity: Activity + + @Inject lateinit var fbCookie: FbCookie @Inject @@ -76,6 +87,9 @@ class FrostWebView @JvmOverloads constructor( @Inject lateinit var cookieDao: CookieDao + @Inject + lateinit var frostWebComponentBuilder: FrostWebComponentBuilder + override fun reload(animate: Boolean) { if (parent.registerTransition(false, animate)) super.reload() @@ -90,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 @@ -103,7 +119,7 @@ class FrostWebView @JvmOverloads constructor( frostWebClient = (container as? WebFragment)?.client(this) ?: FrostWebViewClient(this) webViewClient = frostWebClient webChromeClient = FrostChromeClient(this, themeProvider, webFileChooser) - addJavascriptInterface(FrostJSI(this), "Frost") + addJavascriptInterface(entryPoint.frostJsi(), "Frost") setBackgroundColor(Color.TRANSPARENT) setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength -> context.ctxCoroutine.launchMain { @@ -235,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 +} |