aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/web
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/web')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt48
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt35
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt44
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt34
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt38
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt84
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt36
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/web/NestedWebView.kt46
8 files changed, 276 insertions, 89 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 ac62f142..bb196221 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/DebugWebView.kt
@@ -1,13 +1,29 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Color
-import android.support.annotation.WorkerThread
import android.util.AttributeSet
import android.view.View
import android.webkit.WebView
+import androidx.annotation.WorkerThread
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.injectors.CssAssets
import com.pitchedapps.frost.injectors.CssHider
@@ -25,7 +41,9 @@ import java.io.File
* A barebone webview with a refresh listener
*/
class DebugWebView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {
var onPageFinished: (String?) -> Unit = {}
@@ -71,25 +89,27 @@ class DebugWebView @JvmOverloads constructor(
private fun injectBackgroundColor() {
setBackgroundColor(
- if (url.isFacebookUrl) Prefs.bgColor.withAlpha(255)
- else Color.WHITE)
+ if (url.isFacebookUrl) Prefs.bgColor.withAlpha(255)
+ else Color.WHITE
+ )
}
-
override fun onPageCommitVisible(view: WebView, url: String?) {
super.onPageCommitVisible(view, url)
injectBackgroundColor()
if (url.isFacebookUrl)
view.jsInject(
- CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
+ CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
// CssHider.CORE,
- CssHider.COMPOSER.maybe(!Prefs.showComposer),
- 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))
+ CssHider.COMPOSER.maybe(!Prefs.showComposer),
+ 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
+ )
+ )
}
}
-
-} \ No newline at end of file
+}
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 3c3c063a..12df8000 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostChromeClients.kt
@@ -1,7 +1,27 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.net.Uri
-import android.webkit.*
+import android.webkit.ConsoleMessage
+import android.webkit.GeolocationPermissions
+import android.webkit.ValueCallback
+import android.webkit.WebChromeClient
+import android.webkit.WebView
import ca.allanwang.kau.permissions.PERMISSION_ACCESS_FINE_LOCATION
import ca.allanwang.kau.permissions.kauRequestPermissions
import com.pitchedapps.frost.R
@@ -12,7 +32,6 @@ import com.pitchedapps.frost.views.FrostWebView
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
-
/**
* Created by Allan Wang on 2017-05-31.
*
@@ -45,9 +64,13 @@ class FrostChromeClient(web: FrostWebView) : WebChromeClient() {
progress.onNext(newProgress)
}
- override fun onShowFileChooser(webView: WebView, filePathCallback: ValueCallback<Array<Uri>?>, fileChooserParams: FileChooserParams): Boolean {
+ override fun onShowFileChooser(
+ webView: WebView,
+ filePathCallback: ValueCallback<Array<Uri>?>,
+ fileChooserParams: FileChooserParams
+ ): Boolean {
activity?.openFileChooser(filePathCallback, fileChooserParams)
- ?: webView.frostSnackbar(R.string.file_chooser_not_found)
+ ?: webView.frostSnackbar(R.string.file_chooser_not_found)
return activity != null
}
@@ -58,6 +81,4 @@ class FrostChromeClient(web: FrostWebView) : WebChromeClient() {
callback(origin, granted, true)
}
}
-
-
-} \ No newline at end of file
+}
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 564b0e04..2afb28c9 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostJSI.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.webkit.JavascriptInterface
@@ -5,11 +21,16 @@ import com.pitchedapps.frost.activities.MainActivity
import com.pitchedapps.frost.contracts.MainActivityContract
import com.pitchedapps.frost.contracts.VideoViewHolder
import com.pitchedapps.frost.facebook.FbCookie
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.WebContext
+import com.pitchedapps.frost.utils.cookies
+import com.pitchedapps.frost.utils.isIndependent
+import com.pitchedapps.frost.utils.launchImageActivity
+import com.pitchedapps.frost.utils.showWebContextMenu
import com.pitchedapps.frost.views.FrostWebView
import io.reactivex.subjects.Subject
-
/**
* Created by Allan Wang on 2017-06-01.
*/
@@ -31,15 +52,15 @@ class FrostJSI(val web: FrostWebView) {
@JavascriptInterface
fun loadVideo(url: String?, isGif: Boolean): Boolean =
- if (url != null && Prefs.enablePip) {
- web.post {
- (context as? VideoViewHolder)?.showVideo(url, isGif)
- ?: L.e { "Could not load video; contract not implemented" }
- }
- true
- } else {
- false
+ if (url != null && Prefs.enablePip) {
+ web.post {
+ (context as? VideoViewHolder)?.showVideo(url, isGif)
+ ?: L.e { "Could not load video; contract not implemented" }
}
+ true
+ } else {
+ false
+ }
@JavascriptInterface
fun reloadBaseUrl(animate: Boolean) {
@@ -113,5 +134,4 @@ class FrostJSI(val web: FrostWebView) {
html ?: return
header?.onNext(html)
}
-
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
index 4e4df027..bd696b02 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostRequestInterceptor.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.webkit.WebResourceRequest
@@ -8,14 +24,19 @@ import com.pitchedapps.frost.utils.L
import okhttp3.HttpUrl
import java.io.ByteArrayInputStream
-
/**
* Created by Allan Wang on 2017-07-13.
*
* Handler to decide when a request should be done by us
* This is the crux of Frost's optimizations for the web browser
*/
-private val blankResource: WebResourceResponse by lazy { WebResourceResponse("text/plain", "utf-8", ByteArrayInputStream("".toByteArray())) }
+private val blankResource: WebResourceResponse by lazy {
+ WebResourceResponse(
+ "text/plain",
+ "utf-8",
+ ByteArrayInputStream("".toByteArray())
+ )
+}
fun WebView.shouldFrostInterceptRequest(request: WebResourceRequest): WebResourceResponse? {
val requestUrl = request.url?.toString() ?: return null
@@ -46,12 +67,13 @@ val WebResourceRequest.isMedia: Boolean
* Generic filter passthrough
* If Resource is already nonnull, pass it, otherwise check if filter is met and override the response accordingly
*/
-fun WebResourceResponse?.filter(request: WebResourceRequest, filter: (url: String) -> Boolean) = filter(request.query { filter(it) })
+fun WebResourceResponse?.filter(request: WebResourceRequest, filter: (url: String) -> Boolean) =
+ filter(request.query { filter(it) })
fun WebResourceResponse?.filter(filter: Boolean): WebResourceResponse? = this
- ?: if (filter) blankResource else null
+ ?: if (filter) blankResource else null
-fun WebResourceResponse?.filterCss(request: WebResourceRequest): WebResourceResponse? = filter(request) { it.endsWith(".css") }
+fun WebResourceResponse?.filterCss(request: WebResourceRequest): WebResourceResponse? =
+ filter(request) { it.endsWith(".css") }
fun WebResourceResponse?.filterImage(request: WebResourceRequest): WebResourceResponse? = filter(request.isImage)
-
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 b83002a3..e2d294f7 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import com.pitchedapps.frost.activities.WebOverlayActivity
@@ -8,7 +24,15 @@ import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.USER_AGENT_BASIC
import com.pitchedapps.frost.facebook.formattedFbUrl
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.isImageUrl
+import com.pitchedapps.frost.utils.isIndependent
+import com.pitchedapps.frost.utils.isIndirectImageUrl
+import com.pitchedapps.frost.utils.isVideoUrl
+import com.pitchedapps.frost.utils.launchImageActivity
+import com.pitchedapps.frost.utils.launchWebOverlay
+import com.pitchedapps.frost.utils.launchWebOverlayBasic
import com.pitchedapps.frost.views.FrostWebView
import org.jetbrains.anko.runOnUiThread
@@ -77,14 +101,14 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean {
* If the url contains any one of the whitelist segments, switch to the chat overlay
*/
val messageWhitelist: Set<String> =
- setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES)
- .mapTo(mutableSetOf(), FbItem::url)
+ setOf(FbItem.MESSAGES, FbItem.CHAT, FbItem.FEED_MOST_RECENT, FbItem.FEED_TOP_STORIES)
+ .mapTo(mutableSetOf(), FbItem::url)
val String.shouldUseBasicAgent: Boolean
get() {
- if (contains("story.php")) // do not use basic for comment section
+ if (contains("story.php")) // do not use basic for comment section
return false
- if (contains("/events/")) // do not use for events (namely the map)
+ if (contains("/events/")) // do not use for events (namely the map)
return false
- return true // use for everything else
- } \ No newline at end of file
+ return true // use for everything else
+ }
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 8824e635..d75f03bb 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.graphics.Bitmap
@@ -10,8 +26,19 @@ import com.pitchedapps.frost.facebook.FB_URL_BASE
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.facebook.FbItem
import com.pitchedapps.frost.facebook.formattedFbUrl
-import com.pitchedapps.frost.injectors.*
-import com.pitchedapps.frost.utils.*
+import com.pitchedapps.frost.injectors.CssAssets
+import com.pitchedapps.frost.injectors.CssHider
+import com.pitchedapps.frost.injectors.JsActions
+import com.pitchedapps.frost.injectors.JsAssets
+import com.pitchedapps.frost.injectors.jsInject
+import com.pitchedapps.frost.utils.L
+import com.pitchedapps.frost.utils.Prefs
+import com.pitchedapps.frost.utils.isExplicitIntent
+import com.pitchedapps.frost.utils.isFacebookUrl
+import com.pitchedapps.frost.utils.isImageUrl
+import com.pitchedapps.frost.utils.isIndirectImageUrl
+import com.pitchedapps.frost.utils.launchImageActivity
+import com.pitchedapps.frost.utils.resolveActivityForUri
import com.pitchedapps.frost.views.FrostWebView
import io.reactivex.subjects.Subject
import org.jetbrains.anko.withAlpha
@@ -28,8 +55,8 @@ import org.jetbrains.anko.withAlpha
*/
open class BaseWebViewClient : WebViewClient() {
- override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? = view.shouldFrostInterceptRequest(request)
-
+ override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? =
+ view.shouldFrostInterceptRequest(request)
}
/**
@@ -51,11 +78,11 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
private fun injectBackgroundColor() {
web.setBackgroundColor(
- when {
- isMain -> Color.TRANSPARENT
- web.url.isFacebookUrl -> Prefs.bgColor.withAlpha(255)
- else -> Color.WHITE
- }
+ when {
+ isMain -> Color.TRANSPARENT
+ web.url.isFacebookUrl -> Prefs.bgColor.withAlpha(255)
+ else -> Color.WHITE
+ }
)
}
@@ -64,21 +91,24 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
injectBackgroundColor()
if (url.isFacebookUrl)
view.jsInject(
- CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
+ CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons),
// CssHider.CORE,
- CssHider.HEADER,
- CssHider.COMPOSER.maybe(!Prefs.showComposer),
- 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),
- JsAssets.DOCUMENT_WATCHER,
- JsAssets.CLICK_A,
- CssHider.ADS.maybe(!Prefs.showFacebookAds),
- JsAssets.CONTEXT_A,
+ CssHider.HEADER,
+ CssHider.COMPOSER.maybe(!Prefs.showComposer),
+ 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
+ ),
+ JsAssets.DOCUMENT_WATCHER,
+ JsAssets.CLICK_A,
+ CssHider.ADS.maybe(!Prefs.showFacebookAds),
+ JsAssets.CONTEXT_A,
// JsAssets.HEADER_HIDER,
- JsAssets.MEDIA)
+ JsAssets.MEDIA
+ )
else
refresh.onNext(false)
}
@@ -104,9 +134,10 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
refresh.onNext(false)
injectBackgroundColor()
web.jsInject(
- JsActions.LOGIN_CHECK,
- JsAssets.TEXTAREA_LISTENER,
- JsAssets.HEADER_BADGES.maybe(isMain))
+ JsActions.LOGIN_CHECK,
+ JsAssets.TEXTAREA_LISTENER,
+ JsAssets.HEADER_BADGES.maybe(isMain)
+ )
}
open fun handleHtml(html: String?) {
@@ -151,7 +182,6 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
if (Prefs.linksInDefaultApp && view.context.resolveActivityForUri(request.url)) return true
return super.shouldOverrideUrlLoading(view, request)
}
-
}
private const val EMIT_THEME = 0b1
@@ -189,4 +219,4 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) {
v { "Should inject ${url.shouldInjectMenu}" }
if (!url.shouldInjectMenu) injectAndFinish()
}
-} \ No newline at end of file
+}
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 1f22f303..392cb353 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/LoginWebView.kt
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.annotation.SuppressLint
@@ -5,7 +21,11 @@ import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.View
-import android.webkit.*
+import android.webkit.ConsoleMessage
+import android.webkit.CookieManager
+import android.webkit.WebChromeClient
+import android.webkit.WebResourceRequest
+import android.webkit.WebView
import ca.allanwang.kau.utils.fadeIn
import ca.allanwang.kau.utils.isVisible
import com.pitchedapps.frost.dbflow.CookieModel
@@ -26,7 +46,9 @@ import org.jetbrains.anko.uiThread
* Created by Allan Wang on 2017-05-29.
*/
class LoginWebView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr) {
private lateinit var loginCallback: (CookieModel) -> Unit
@@ -73,9 +95,11 @@ class LoginWebView @JvmOverloads constructor(
L.d { "Login page commit visible" }
view.setBackgroundColor(Color.TRANSPARENT)
if (url.isFacebookUrl)
- view.jsInject(JsAssets.HEADER_HIDER,
- CssHider.CORE,
- Prefs.themeInjector)
+ view.jsInject(
+ JsAssets.HEADER_HIDER,
+ CssHider.CORE,
+ Prefs.themeInjector
+ )
}
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
@@ -97,4 +121,4 @@ class LoginWebView @JvmOverloads constructor(
progressCallback(newProgress)
}
}
-} \ No newline at end of file
+}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/NestedWebView.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/NestedWebView.kt
index 297c4158..6e7fc0b6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/web/NestedWebView.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/web/NestedWebView.kt
@@ -1,14 +1,29 @@
+/*
+ * Copyright 2018 Allan Wang
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
package com.pitchedapps.frost.web
import android.annotation.SuppressLint
import android.content.Context
-import android.support.v4.view.NestedScrollingChild
-import android.support.v4.view.NestedScrollingChildHelper
-import android.support.v4.view.ViewCompat
import android.util.AttributeSet
import android.view.MotionEvent
import android.webkit.WebView
-
+import androidx.core.view.NestedScrollingChild
+import androidx.core.view.NestedScrollingChildHelper
+import androidx.core.view.ViewCompat
/**
* Created by Allan Wang on 20/12/17.
@@ -16,7 +31,9 @@ import android.webkit.WebView
* Webview extension that handles nested scrolls
*/
open class NestedWebView @JvmOverloads constructor(
- context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
) : WebView(context, attrs, defStyleAttr), NestedScrollingChild {
private lateinit var childHelper: NestedScrollingChildHelper
@@ -99,11 +116,20 @@ open class NestedWebView @JvmOverloads constructor(
final override fun hasNestedScrollingParent() = childHelper.hasNestedScrollingParent()
- final override fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?) = childHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow)
+ final override fun dispatchNestedScroll(
+ dxConsumed: Int,
+ dyConsumed: Int,
+ dxUnconsumed: Int,
+ dyUnconsumed: Int,
+ offsetInWindow: IntArray?
+ ) = childHelper.dispatchNestedScroll(dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed, offsetInWindow)
- final override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?) = childHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
+ final override fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?) =
+ childHelper.dispatchNestedPreScroll(dx, dy, consumed, offsetInWindow)
- final override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean) = childHelper.dispatchNestedFling(velocityX, velocityY, consumed)
+ final override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean) =
+ childHelper.dispatchNestedFling(velocityX, velocityY, consumed)
- final override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float) = childHelper.dispatchNestedPreFling(velocityX, velocityY)
-} \ No newline at end of file
+ final override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float) =
+ childHelper.dispatchNestedPreFling(velocityX, velocityY)
+}