mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 19:11:50 +01:00
Use AndroidX WebKit library
This commit is contained in:
parent
6c9b982104
commit
7e7eb9f39f
@ -134,6 +134,7 @@ dependencies {
|
|||||||
implementation 'androidx.browser:browser:1.2.0'
|
implementation 'androidx.browser:browser:1.2.0'
|
||||||
implementation 'androidx.multidex:multidex:2.0.1'
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
implementation 'androidx.biometric:biometric:1.0.1'
|
implementation 'androidx.biometric:biometric:1.0.1'
|
||||||
|
implementation 'androidx.webkit:webkit:1.3.0-beta01'
|
||||||
|
|
||||||
final lifecycle_version = '2.2.0'
|
final lifecycle_version = '2.2.0'
|
||||||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
|
||||||
|
@ -2,15 +2,17 @@ package eu.kanade.tachiyomi.network
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
|
import android.webkit.WebResourceResponse
|
||||||
import android.webkit.WebSettings
|
import android.webkit.WebSettings
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.webkit.WebViewClientCompat
|
||||||
|
import androidx.webkit.WebViewFeature
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
|
||||||
import eu.kanade.tachiyomi.util.system.isOutdated
|
import eu.kanade.tachiyomi.util.system.isOutdated
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -103,7 +105,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HTTP error codes are only received since M
|
// HTTP error codes are only received since M
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
|
if (WebViewFeature.isFeatureSupported(WebViewFeature.RECEIVE_WEB_RESOURCE_ERROR) &&
|
||||||
url == origRequestUrl && !challengeFound
|
url == origRequestUrl && !challengeFound
|
||||||
) {
|
) {
|
||||||
// The first request didn't return the challenge, abort.
|
// The first request didn't return the challenge, abort.
|
||||||
@ -111,16 +113,14 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onReceivedErrorCompat(
|
override fun onReceivedHttpError(
|
||||||
view: WebView,
|
view: WebView,
|
||||||
errorCode: Int,
|
request: WebResourceRequest,
|
||||||
description: String?,
|
errorResponse: WebResourceResponse
|
||||||
failingUrl: String,
|
|
||||||
isMainFrame: Boolean
|
|
||||||
) {
|
) {
|
||||||
if (isMainFrame) {
|
if (request.isForMainFrame) {
|
||||||
if (errorCode == 503) {
|
if (errorResponse.statusCode == 503) {
|
||||||
// Found the cloudflare challenge page.
|
// Found the Cloudflare challenge page.
|
||||||
challengeFound = true
|
challengeFound = true
|
||||||
} else {
|
} else {
|
||||||
// Unlock thread, the challenge wasn't found.
|
// Unlock thread, the challenge wasn't found.
|
||||||
|
@ -9,8 +9,10 @@ import android.os.Bundle
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
|
import androidx.webkit.WebViewClientCompat
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
||||||
@ -18,7 +20,6 @@ import eu.kanade.tachiyomi.source.SourceManager
|
|||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
|
import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
|
||||||
import eu.kanade.tachiyomi.util.system.WebViewClientCompat
|
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
@ -92,8 +93,8 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
binding.webview.webViewClient = object : WebViewClientCompat() {
|
binding.webview.webViewClient = object : WebViewClientCompat() {
|
||||||
override fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
|
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
|
||||||
view.loadUrl(url)
|
view.loadUrl(request.url.toString())
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
|||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageCommitVisible(view: WebView?, url: String?) {
|
override fun onPageCommitVisible(view: WebView, url: String) {
|
||||||
super.onPageCommitVisible(view, url)
|
super.onPageCommitVisible(view, url)
|
||||||
|
|
||||||
// Reset to top when page refreshes
|
// Reset to top when page refreshes
|
||||||
|
@ -1,91 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.util.system
|
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.os.Build
|
|
||||||
import android.webkit.WebResourceError
|
|
||||||
import android.webkit.WebResourceRequest
|
|
||||||
import android.webkit.WebResourceResponse
|
|
||||||
import android.webkit.WebView
|
|
||||||
import android.webkit.WebViewClient
|
|
||||||
|
|
||||||
@Suppress("OverridingDeprecatedMember")
|
|
||||||
abstract class WebViewClientCompat : WebViewClient() {
|
|
||||||
|
|
||||||
open fun shouldOverrideUrlCompat(view: WebView, url: String): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun shouldInterceptRequestCompat(view: WebView, url: String): WebResourceResponse? {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun onReceivedErrorCompat(
|
|
||||||
view: WebView,
|
|
||||||
errorCode: Int,
|
|
||||||
description: String?,
|
|
||||||
failingUrl: String,
|
|
||||||
isMainFrame: Boolean
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
|
||||||
final override fun shouldOverrideUrlLoading(
|
|
||||||
view: WebView,
|
|
||||||
request: WebResourceRequest
|
|
||||||
): Boolean {
|
|
||||||
return shouldOverrideUrlCompat(view, request.url.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
|
||||||
return shouldOverrideUrlCompat(view, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun shouldInterceptRequest(
|
|
||||||
view: WebView,
|
|
||||||
request: WebResourceRequest
|
|
||||||
): WebResourceResponse? {
|
|
||||||
return shouldInterceptRequestCompat(view, request.url.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun shouldInterceptRequest(
|
|
||||||
view: WebView,
|
|
||||||
url: String
|
|
||||||
): WebResourceResponse? {
|
|
||||||
return shouldInterceptRequestCompat(view, url)
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
|
||||||
final override fun onReceivedError(
|
|
||||||
view: WebView,
|
|
||||||
request: WebResourceRequest,
|
|
||||||
error: WebResourceError
|
|
||||||
) {
|
|
||||||
onReceivedErrorCompat(
|
|
||||||
view, error.errorCode, error.description?.toString(),
|
|
||||||
request.url.toString(), request.isForMainFrame
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun onReceivedError(
|
|
||||||
view: WebView,
|
|
||||||
errorCode: Int,
|
|
||||||
description: String?,
|
|
||||||
failingUrl: String
|
|
||||||
) {
|
|
||||||
onReceivedErrorCompat(view, errorCode, description, failingUrl, failingUrl == view.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.M)
|
|
||||||
final override fun onReceivedHttpError(
|
|
||||||
view: WebView,
|
|
||||||
request: WebResourceRequest,
|
|
||||||
error: WebResourceResponse
|
|
||||||
) {
|
|
||||||
onReceivedErrorCompat(
|
|
||||||
view, error.statusCode, error.reasonPhrase,
|
|
||||||
request.url
|
|
||||||
.toString(),
|
|
||||||
request.isForMainFrame
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user