优化
This commit is contained in:
@@ -28,6 +28,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.apache.commons.text.StringEscapeUtils
|
import org.apache.commons.text.StringEscapeUtils
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -317,20 +318,47 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
|
|
||||||
override fun shouldOverrideUrlLoading(
|
override fun shouldOverrideUrlLoading(
|
||||||
view: WebView,
|
view: WebView,
|
||||||
request: WebResourceRequest?
|
request: WebResourceRequest
|
||||||
): Boolean {
|
): Boolean {
|
||||||
request?.let {
|
return shouldOverrideUrlLoading(request.url)
|
||||||
return shouldOverrideUrlLoading(it.url)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION", "KotlinRedundantDiagnosticSuppress")
|
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION", "KotlinRedundantDiagnosticSuppress")
|
||||||
override fun shouldOverrideUrlLoading(view: WebView, url: String?): Boolean {
|
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
|
||||||
url?.let {
|
return shouldOverrideUrlLoading(Uri.parse(url))
|
||||||
return shouldOverrideUrlLoading(Uri.parse(it))
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果有黑名单,黑名单匹配返回空白
|
||||||
|
* 没有黑名单再判断白名单,在白名单中的才通过
|
||||||
|
* 都没有不做处理
|
||||||
|
*/
|
||||||
|
override fun shouldInterceptRequest(
|
||||||
|
view: WebView,
|
||||||
|
request: WebResourceRequest
|
||||||
|
): WebResourceResponse? {
|
||||||
|
val url = request.url.toString()
|
||||||
|
viewModel.rssSource?.let {source ->
|
||||||
|
val blacklist = source.contentBlacklist?.splitNotBlank(",")
|
||||||
|
if (!blacklist.isNullOrEmpty()) {
|
||||||
|
blacklist.forEach {
|
||||||
|
if (url.matches(it.toRegex())) {
|
||||||
|
return createEmptyResource()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val whitelist = source.contentWhitelist?.splitNotBlank(",")
|
||||||
|
if (!whitelist.isNullOrEmpty()) {
|
||||||
|
whitelist.forEach {
|
||||||
|
if (url.matches(it.toRegex())) {
|
||||||
|
return super.shouldInterceptRequest(view, request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return createEmptyResource()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return super.shouldInterceptRequest(view, request)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageFinished(view: WebView, url: String?) {
|
override fun onPageFinished(view: WebView, url: String?) {
|
||||||
@@ -349,6 +377,14 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createEmptyResource(): WebResourceResponse {
|
||||||
|
return WebResourceResponse(
|
||||||
|
"text/plain",
|
||||||
|
"utf-8",
|
||||||
|
ByteArrayInputStream("".toByteArray())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun shouldOverrideUrlLoading(url: Uri): Boolean {
|
private fun shouldOverrideUrlLoading(url: Uri): Boolean {
|
||||||
when (url.scheme) {
|
when (url.scheme) {
|
||||||
"http", "https" -> {
|
"http", "https" -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user