From f4348df8709529b7b2319485fc8eb54c6e8173c7 Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:42:14 +0600 Subject: [PATCH] Remove WebViewClientCompat --- .../interceptor/CloudflareInterceptor.kt | 18 ++-- .../util/system/WebViewClientCompat.kt | 88 ------------------- 2 files changed, 7 insertions(+), 99 deletions(-) delete mode 100644 core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt diff --git a/core/common/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/core/common/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index 6a765c680..3522dea4f 100644 --- a/core/common/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/core/common/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -2,11 +2,13 @@ package eu.kanade.tachiyomi.network.interceptor import android.annotation.SuppressLint import android.content.Context +import android.webkit.WebResourceError +import android.webkit.WebResourceRequest import android.webkit.WebView +import android.webkit.WebViewClient import android.widget.Toast import androidx.core.content.ContextCompat import eu.kanade.tachiyomi.network.AndroidCookieJar -import eu.kanade.tachiyomi.util.system.WebViewClientCompat import eu.kanade.tachiyomi.util.system.isOutdated import eu.kanade.tachiyomi.util.system.toast import okhttp3.Cookie @@ -73,7 +75,7 @@ class CloudflareInterceptor( executor.execute { webview = createWebView(originalRequest) - webview?.webViewClient = object : WebViewClientCompat() { + webview?.webViewClient = object : WebViewClient() { override fun onPageFinished(view: WebView, url: String) { fun isCloudFlareBypassed(): Boolean { return cookieManager.get(origRequestUrl.toHttpUrl()) @@ -92,15 +94,9 @@ class CloudflareInterceptor( } } - override fun onReceivedErrorCompat( - view: WebView, - errorCode: Int, - description: String?, - failingUrl: String, - isMainFrame: Boolean, - ) { - if (isMainFrame) { - if (errorCode in ERROR_CODES) { + override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) { + if (request.isForMainFrame) { + if (error.errorCode in ERROR_CODES) { // Found the Cloudflare challenge page. challengeFound = true } else { diff --git a/core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt b/core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt deleted file mode 100644 index 6547a46e0..000000000 --- a/core/common/src/main/kotlin/eu/kanade/tachiyomi/util/system/WebViewClientCompat.kt +++ /dev/null @@ -1,88 +0,0 @@ -package eu.kanade.tachiyomi.util.system - -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, - ) { - } - - 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) - } - - 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) - } - - final override fun onReceivedHttpError( - view: WebView, - request: WebResourceRequest, - error: WebResourceResponse, - ) { - onReceivedErrorCompat( - view, - error.statusCode, - error.reasonPhrase, - request.url - .toString(), - request.isForMainFrame, - ) - } -}