优化代码

pull/736/head
gedoor 4 years ago
parent 4804994669
commit d6429d35b6
  1. 18
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt

@ -160,8 +160,12 @@ class AjaxWebView {
if (it.isNotEmpty() && it != "null") { if (it.isNotEmpty() && it != "null") {
val content = StringEscapeUtils.unescapeJson(it) val content = StringEscapeUtils.unescapeJson(it)
.replace("^\"|\"$".toRegex(), "") .replace("^\"|\"$".toRegex(), "")
handler.obtainMessage(MSG_SUCCESS, StrResponse(url, content)) try {
.sendToTarget() val response = StrResponse(url, content)
handler.obtainMessage(MSG_SUCCESS, response).sendToTarget()
} catch (e: Exception) {
handler.obtainMessage(MSG_ERROR, e).sendToTarget()
}
handler.removeCallbacks(this) handler.removeCallbacks(this)
return@evaluateJavascript return@evaluateJavascript
} }
@ -186,10 +190,12 @@ class AjaxWebView {
override fun onLoadResource(view: WebView, url: String) { override fun onLoadResource(view: WebView, url: String) {
params.sourceRegex?.let { params.sourceRegex?.let {
if (url.matches(it.toRegex())) { if (url.matches(it.toRegex())) {
handler.obtainMessage( try {
MSG_SUCCESS, val response = StrResponse(view.url ?: params.url, url)
StrResponse(view.url ?: params.url, url) handler.obtainMessage(MSG_SUCCESS, response).sendToTarget()
).sendToTarget() } catch (e: Exception) {
handler.obtainMessage(MSG_ERROR, e).sendToTarget()
}
} }
} }
} }

Loading…
Cancel
Save