feat(ui/browser):支持返回网页结果

pull/1841/head
Xwite 3 years ago
parent 4c83e00bf8
commit c389d43e7f
  1. 6
      app/src/main/java/io/legado/app/ui/browser/WebViewActivity.kt
  2. 9
      app/src/main/java/io/legado/app/ui/browser/WebViewModel.kt

@ -177,6 +177,7 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
binding.webView.destroy() binding.webView.destroy()
viewModel.saveVerificationResult()
} }
inner class CustomWebChromeClient : WebChromeClient() { inner class CustomWebChromeClient : WebChromeClient() {
@ -215,6 +216,11 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
return true return true
} }
override fun onLoadResource(view: WebView, resUrl: String) {
if (viewModel.sourceVerificationEnable) viewModel.html = resUrl
}
override fun onPageFinished(view: WebView?, url: String?) { override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url) super.onPageFinished(view, url)
val cookieManager = CookieManager.getInstance() val cookieManager = CookieManager.getInstance()

@ -9,6 +9,7 @@ import androidx.documentfile.provider.DocumentFile
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.CacheManager
import io.legado.app.help.IntentData import io.legado.app.help.IntentData
import io.legado.app.help.http.newCallResponseBody import io.legado.app.help.http.newCallResponseBody
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
@ -21,6 +22,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
var baseUrl: String = "" var baseUrl: String = ""
var html: String? = null var html: String? = null
val headerMap: HashMap<String, String> = hashMapOf() val headerMap: HashMap<String, String> = hashMapOf()
var sourceVerificationEnable: Boolean = false
fun initData( fun initData(
intent: Intent, intent: Intent,
@ -29,6 +31,7 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
execute { execute {
val url = intent.getStringExtra("url") val url = intent.getStringExtra("url")
?: throw NoStackTraceException("url不能为空") ?: throw NoStackTraceException("url不能为空")
sourceVerificationEnable = intent.getBooleanExtra("sourceVerificationEnable") ?: false
val headerMapF = IntentData.get<Map<String, String>>(url) val headerMapF = IntentData.get<Map<String, String>>(url)
val analyzeUrl = AnalyzeUrl(url, headerMapF = headerMapF) val analyzeUrl = AnalyzeUrl(url, headerMapF = headerMapF)
baseUrl = analyzeUrl.url baseUrl = analyzeUrl.url
@ -78,5 +81,11 @@ class WebViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun saveVerificationResult() {
if (sourceVerificationEnable) {
val key = "${baseUrl}_verificationResult"
CacheManager.put(key, html!!)
}
}
} }
Loading…
Cancel
Save