Merge pull request #2508 from 821938089/little-fix

一些优化
This commit is contained in:
Horis 2022-10-31 14:45:32 +08:00 committed by GitHub
commit ffbd212666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -34,6 +34,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
private val imagePathKey = "imagePath"
private var customWebViewCallback: WebChromeClient.CustomViewCallback? = null
private var webPic: String? = null
private var isCloudflareChallenge = false
private val saveImage = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
ACache.get().put(imagePathKey, uri.toString())
@ -68,7 +69,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
R.id.menu_copy_url -> sendToClip(viewModel.baseUrl)
R.id.menu_ok -> {
if (viewModel.sourceVerificationEnable) {
viewModel.saveVerificationResult {
viewModel.saveVerificationResult(intent) {
finish()
}
} else {
@ -226,6 +227,16 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
} else {
binding.titleBar.title = intent.getStringExtra("title")
}
if (title == "Just a moment...") {
isCloudflareChallenge = true
}
if (isCloudflareChallenge && title != "Just a moment...") {
if (viewModel.sourceVerificationEnable) {
viewModel.saveVerificationResult(intent) {
finish()
}
}
}
}
}

View File

@ -8,6 +8,7 @@ import android.webkit.URLUtil
import androidx.documentfile.provider.DocumentFile
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.data.appDb
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.CacheManager
import io.legado.app.help.IntentData
@ -83,11 +84,17 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
}
}
fun saveVerificationResult(success: () -> Unit) {
fun saveVerificationResult(intent: Intent, success: () -> Unit) {
execute {
if (sourceVerificationEnable) {
val url = intent.getStringExtra("url")!!
val source = appDb.bookSourceDao.getBookSource(sourceOrigin)
val key = "${sourceOrigin}_verificationResult"
html = AnalyzeUrl(baseUrl, headerMapF = headerMap).getStrResponseAwait(useWebView = false).body
html = AnalyzeUrl(
url,
headerMapF = headerMap,
source = source
).getStrResponseAwait(useWebView = false).body
CacheManager.putMemory(key, html ?: "")
}
}.onSuccess {