Remove unused WebViewClientCompat
This commit is contained in:
@@ -2,10 +2,9 @@ package org.koitharu.kotatsu.browser
|
|||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import org.koin.core.component.KoinComponent
|
import android.webkit.WebViewClient
|
||||||
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
|
||||||
|
|
||||||
class BrowserClient(private val callback: BrowserCallback) : WebViewClientCompat(), KoinComponent {
|
class BrowserClient(private val callback: BrowserCallback) : WebViewClient() {
|
||||||
|
|
||||||
override fun onPageFinished(webView: WebView, url: String) {
|
override fun onPageFinished(webView: WebView, url: String) {
|
||||||
super.onPageFinished(webView, url)
|
super.onPageFinished(webView, url)
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ package org.koitharu.kotatsu.browser
|
|||||||
|
|
||||||
import android.webkit.WebChromeClient
|
import android.webkit.WebChromeClient
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
import android.widget.ProgressBar
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.google.android.material.progressindicator.BaseProgressIndicator
|
import org.koitharu.kotatsu.utils.ext.setProgressCompat
|
||||||
|
|
||||||
private const val PROGRESS_MAX = 100
|
private const val PROGRESS_MAX = 100
|
||||||
|
|
||||||
class ProgressChromeClient(
|
class ProgressChromeClient(
|
||||||
private val progressIndicator: BaseProgressIndicator<*>,
|
private val progressIndicator: ProgressBar,
|
||||||
) : WebChromeClient() {
|
) : WebChromeClient() {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -24,7 +25,7 @@ class ProgressChromeClient(
|
|||||||
progressIndicator.isIndeterminate = false
|
progressIndicator.isIndeterminate = false
|
||||||
progressIndicator.setProgressCompat(newProgress.coerceAtMost(PROGRESS_MAX), true)
|
progressIndicator.setProgressCompat(newProgress.coerceAtMost(PROGRESS_MAX), true)
|
||||||
} else {
|
} else {
|
||||||
progressIndicator.setIndeterminate(true)
|
progressIndicator.isIndeterminate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,19 @@ package org.koitharu.kotatsu.browser.cloudflare
|
|||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
import android.webkit.WebViewClient
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
import org.koitharu.kotatsu.core.network.AndroidCookieJar
|
||||||
import org.koitharu.kotatsu.core.network.WebViewClientCompat
|
|
||||||
|
|
||||||
private const val CF_CLEARANCE = "cf_clearance"
|
private const val CF_CLEARANCE = "cf_clearance"
|
||||||
|
|
||||||
class CloudFlareClient(
|
class CloudFlareClient(
|
||||||
private val cookieJar: AndroidCookieJar,
|
private val cookieJar: AndroidCookieJar,
|
||||||
private val callback: CloudFlareCallback,
|
private val callback: CloudFlareCallback,
|
||||||
private val targetUrl: String
|
private val targetUrl: String,
|
||||||
) : WebViewClientCompat() {
|
) : WebViewClient() {
|
||||||
|
|
||||||
private val oldClearance = getCookieValue(CF_CLEARANCE)
|
private val oldClearance = getClearance()
|
||||||
|
|
||||||
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
||||||
super.onPageStarted(view, url, favicon)
|
super.onPageStarted(view, url, favicon)
|
||||||
@@ -32,14 +32,14 @@ class CloudFlareClient(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkClearance() {
|
private fun checkClearance() {
|
||||||
val clearance = getCookieValue(CF_CLEARANCE)
|
val clearance = getClearance()
|
||||||
if (clearance != null && clearance != oldClearance) {
|
if (clearance != null && clearance != oldClearance) {
|
||||||
callback.onCheckPassed()
|
callback.onCheckPassed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCookieValue(name: String): String? {
|
private fun getClearance(): String? {
|
||||||
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
return cookieJar.loadForRequest(targetUrl.toHttpUrl())
|
||||||
.find { it.name == name }?.value
|
.find { it.name == CF_CLEARANCE }?.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.core.network
|
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.os.Build
|
|
||||||
import android.webkit.*
|
|
||||||
|
|
||||||
@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 = 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? = shouldInterceptRequestCompat(view, request.url.toString())
|
|
||||||
|
|
||||||
final override fun shouldInterceptRequest(
|
|
||||||
view: WebView,
|
|
||||||
url: String
|
|
||||||
): WebResourceResponse? = 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
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user