diff --git a/app/cronetlib/cronet_api.jar b/app/cronetlib/cronet_api.jar index d62e993bb..5f322b8f8 100644 Binary files a/app/cronetlib/cronet_api.jar and b/app/cronetlib/cronet_api.jar differ diff --git a/app/cronetlib/cronet_impl_common_java.jar b/app/cronetlib/cronet_impl_common_java.jar index f851e7120..4d627c1f2 100644 Binary files a/app/cronetlib/cronet_impl_common_java.jar and b/app/cronetlib/cronet_impl_common_java.jar differ diff --git a/app/cronetlib/src/cronet_api-src.jar b/app/cronetlib/src/cronet_api-src.jar index 78bf99a0e..6c11000c0 100644 Binary files a/app/cronetlib/src/cronet_api-src.jar and b/app/cronetlib/src/cronet_api-src.jar differ diff --git a/app/cronetlib/src/cronet_impl_common_java-src.jar b/app/cronetlib/src/cronet_impl_common_java-src.jar index 7d7da6f33..d4e43c622 100644 Binary files a/app/cronetlib/src/cronet_impl_common_java-src.jar and b/app/cronetlib/src/cronet_impl_common_java-src.jar differ diff --git a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt index 0a0e955b3..3bc10e838 100644 --- a/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt +++ b/app/src/main/java/io/legado/app/help/http/cronet/CronetInterceptor.kt @@ -27,7 +27,12 @@ class CronetInterceptor(private val cookieJar: CookieJar?) : Interceptor { response } catch (e: Exception) { //遇到Cronet处理有问题时的情况,如证书过期等等,回退到okhttp处理 - chain.proceed(original) + if (e.message.toString().contains("ERR_CERT_DATE_INVALID", true)) { + chain.proceed(original) + } else { + throw e + } + } diff --git a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt index 27f2724a2..96e10d0d4 100644 --- a/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/dict/DictViewModel.kt @@ -8,12 +8,27 @@ import io.legado.app.help.http.newCallStrResponse import io.legado.app.help.http.okHttpClient import io.legado.app.utils.toastOnUi import org.jsoup.Jsoup +import java.util.regex.Pattern class DictViewModel(application: Application) : BaseViewModel(application) { var dictHtmlData: MutableLiveData = MutableLiveData() fun dict(word: String) { + if(isChinese(word)){ + baiduDict(word) + }else{ + haiciDict(word) + } + + } + + /** + * 海词英文词典 + * + * @param word + */ + private fun haiciDict(word: String) { execute { val body = okHttpClient.newCallStrResponse { get("https://apii.dict.cn/mini.php", mapOf(Pair("q", word))) @@ -25,7 +40,44 @@ class DictViewModel(application: Application) : BaseViewModel(application) { }.onError { context.toastOnUi(it.localizedMessage) } + } + + /** + * 百度汉语词典 + * + * @param word + */ + private fun baiduDict(word: String) { + execute { + val body = okHttpClient.newCallStrResponse { + get("https://dict.baidu.com/s", mapOf(Pair("wd", word))) + }.body + val jsoup = Jsoup.parse(body!!) + jsoup.select("script").remove()//移除script + jsoup.select("#word-header").remove()//移除单字的header + jsoup.select("#term-header").remove()//移除词语的header + jsoup.select(".more-button").remove()//移除展示更多 + jsoup.select(".disactive").remove() + jsoup.select("#download-wrapper").remove()//移除下载广告 + jsoup.select("#right-panel").remove()//移除右侧广告 + jsoup.select("#content-panel") + }.onSuccess { + dictHtmlData.postValue(it.html()) + }.onError { + context.toastOnUi(it.localizedMessage) + } + } + + /** + * 判断是否包含汉字 + * @param str + * @return + */ + fun isChinese(str: String): Boolean { + val p = Pattern.compile("[\u4e00-\u9fa5]") + val m = p.matcher(str) + return m.find() } } \ No newline at end of file