diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt | 13 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt | 41 |
2 files changed, 27 insertions, 27 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt index e687dd2d..61a76e70 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt @@ -30,11 +30,9 @@ import ca.allanwang.kau.permissions.kauRequestPermissions import ca.allanwang.kau.utils.materialDialog import com.afollestad.materialdialogs.callbacks.onDismiss import com.afollestad.materialdialogs.input.input -import com.pitchedapps.frost.R -import com.pitchedapps.frost.contracts.ActivityContract +import com.pitchedapps.frost.contracts.WebFileChooser import com.pitchedapps.frost.injectors.ThemeProvider import com.pitchedapps.frost.utils.L -import com.pitchedapps.frost.utils.frostSnackbar import com.pitchedapps.frost.views.FrostWebView import kotlinx.coroutines.channels.SendChannel @@ -49,13 +47,13 @@ import kotlinx.coroutines.channels.SendChannel */ class FrostChromeClient( web: FrostWebView, - private val themeProvider: ThemeProvider + private val themeProvider: ThemeProvider, + private val webFileChooser: WebFileChooser, ) : WebChromeClient() { private val refresh: SendChannel<Boolean> = web.parent.refreshChannel private val progress: SendChannel<Int> = web.parent.progressChannel private val title: SendChannel<String> = web.parent.titleChannel - private val activity = (web.context as? ActivityContract) private val context = web.context!! override fun getDefaultVideoPoster(): Bitmap? = @@ -83,9 +81,8 @@ class FrostChromeClient( filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: FileChooserParams ): Boolean { - activity?.openFileChooser(filePathCallback, fileChooserParams) - ?: webView.frostSnackbar(R.string.file_chooser_not_found, themeProvider) - return activity != null + webFileChooser.openMediaPicker(filePathCallback, fileChooserParams) + return true } private fun JsResult.frostCancel() { 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 9a853dae..3ead78f4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt @@ -16,12 +16,11 @@ */ package com.pitchedapps.frost.web -import android.content.Context +import android.app.Activity import android.webkit.JavascriptInterface import ca.allanwang.kau.utils.ctxCoroutine import com.pitchedapps.frost.activities.MainActivity import com.pitchedapps.frost.activities.WebOverlayActivityBase -import com.pitchedapps.frost.contracts.MainActivityContract import com.pitchedapps.frost.contracts.VideoViewHolder import com.pitchedapps.frost.db.CookieEntity import com.pitchedapps.frost.facebook.FbCookie @@ -35,19 +34,23 @@ import com.pitchedapps.frost.utils.showWebContextMenu import com.pitchedapps.frost.views.FrostWebView import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.launch +import javax.inject.Inject /** * Created by Allan Wang on 2017-06-01. */ -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 +class FrostJSI @Inject internal constructor( + val web: FrostWebView, + private val activity: Activity, + private val fbCookie: FbCookie, + private val prefs: Prefs +) { + + private val mainActivity: MainActivity? = activity as? MainActivity + private val webActivity: WebOverlayActivityBase? = activity as? WebOverlayActivityBase + private val header: SendChannel<String>? = mainActivity?.headerBadgeChannel private val refresh: SendChannel<Boolean> = web.parent.refreshChannel - private val cookies: List<CookieEntity> = activity?.cookies() ?: arrayListOf() + private val cookies: List<CookieEntity> = activity.cookies() /** * Attempts to load the url in an overlay @@ -61,7 +64,7 @@ class FrostJSI(val web: FrostWebView) { fun loadVideo(url: String?, isGif: Boolean): Boolean = if (url != null && prefs.enablePip) { web.post { - (context as? VideoViewHolder)?.showVideo(url, isGif) + (activity as? VideoViewHolder)?.showVideo(url, isGif) ?: L.e { "Could not load video; contract not implemented" } } true @@ -82,7 +85,7 @@ class FrostJSI(val web: FrostWebView) { fun contextMenu(url: String?, text: String?) { // url will be formatted through webcontext web.post { - context.showWebContextMenu( + activity.showWebContextMenu( WebContext(url.takeIf { it.isIndependent }, text), fbCookie, prefs @@ -96,7 +99,7 @@ class FrostJSI(val web: FrostWebView) { */ @JavascriptInterface fun longClick(start: Boolean) { - activity?.contentBinding?.viewpager?.enableSwipe = !start + mainActivity?.contentBinding?.viewpager?.enableSwipe = !start if (web.frostWebClient.urlSupportsRefresh) { web.parent.swipeDisabledByAction = start } @@ -113,15 +116,15 @@ class FrostJSI(val web: FrostWebView) { web.parent.swipeDisabledByAction = disable if (disable) { // locked onto an input field; ensure content is visible - (context as? MainActivityContract)?.collapseAppBar() + mainActivity?.collapseAppBar() } } @JavascriptInterface fun loadLogin() { L.d { "Sign up button found; load login" } - context.ctxCoroutine.launch { - fbCookie.logout(context, deleteCookie = false) + activity.ctxCoroutine.launch { + fbCookie.logout(activity, deleteCookie = false) } } @@ -130,7 +133,7 @@ class FrostJSI(val web: FrostWebView) { */ @JavascriptInterface fun loadImage(imageUrl: String, text: String?) { - context.launchImageActivity(imageUrl, text) + activity.launchImageActivity(imageUrl, text) } @JavascriptInterface @@ -159,8 +162,8 @@ class FrostJSI(val web: FrostWebView) { @JavascriptInterface fun allowHorizontalScrolling(enable: Boolean) { - activity?.contentBinding?.viewpager?.enableSwipe = enable - (context as? WebOverlayActivityBase)?.swipeBack?.disallowIntercept = !enable + mainActivity?.contentBinding?.viewpager?.enableSwipe = enable + webActivity?.swipeBack?.disallowIntercept = !enable } private var isScrolling = false |