From 86cb09a83b57fbcc9592f5d415841c0db1927efa Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 5 Apr 2021 11:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E8=AF=95=E8=AE=A2=E9=98=85=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E7=9C=8B=E6=BA=90=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 3 ++- .../main/java/io/legado/app/model/rss/Rss.kt | 7 +++++-- .../legado/app/model/rss/RssParserByRule.kt | 1 + .../app/ui/rss/read/ReadRssViewModel.kt | 20 ++++++++++--------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 65e83f278..53feb4054 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -334,7 +334,8 @@ interface JsExtensions { /** * 输出调试日志 */ - fun log(msg: String) { + fun log(msg: String): String { Debug.log(msg) + return msg } } diff --git a/app/src/main/java/io/legado/app/model/rss/Rss.kt b/app/src/main/java/io/legado/app/model/rss/Rss.kt index 71aa5b2b3..d86095390 100644 --- a/app/src/main/java/io/legado/app/model/rss/Rss.kt +++ b/app/src/main/java/io/legado/app/model/rss/Rss.kt @@ -3,6 +3,7 @@ package io.legado.app.model.rss import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.Debug import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleData @@ -38,7 +39,7 @@ object Rss { scope: CoroutineScope, rssArticle: RssArticle, ruleContent: String, - rssSource: RssSource?, + rssSource: RssSource, context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { @@ -46,9 +47,11 @@ object Rss { rssArticle.link, baseUrl = rssArticle.origin, ruleData = rssArticle, - headerMapF = rssSource?.getHeaderMap() + headerMapF = rssSource.getHeaderMap() ) val body = analyzeUrl.getStrResponse(rssArticle.origin).body + Debug.log(rssSource.sourceUrl, "≡获取成功:${rssSource.sourceUrl}") + Debug.log(rssSource.sourceUrl, body, state = 20) val analyzeRule = AnalyzeRule(rssArticle) analyzeRule.setContent(body) .setBaseUrl(NetworkUtils.getAbsoluteURL(rssArticle.origin, rssArticle.link)) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index e2b702cce..6affe0b88 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -31,6 +31,7 @@ object RssParserByRule { ) } Debug.log(sourceUrl, "≡获取成功:$sourceUrl") + Debug.log(sourceUrl, body, state = 10) var ruleArticles = rssSource.ruleArticles if (ruleArticles.isNullOrBlank()) { Debug.log(sourceUrl, "⇒列表规则为空, 使用默认规则解析") diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index cf3574f2e..a2faacfad 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -94,16 +94,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } private fun loadContent(rssArticle: RssArticle, ruleContent: String) { - Rss.getContent(this, rssArticle, ruleContent, rssSource) - .onSuccess(IO) { body -> - rssArticle.description = body - appDb.rssArticleDao.insert(rssArticle) - rssStar?.let { - it.description = body - appDb.rssStarDao.insert(it) + rssSource?.let { source -> + Rss.getContent(this, rssArticle, ruleContent, source) + .onSuccess(IO) { body -> + rssArticle.description = body + appDb.rssArticleDao.insert(rssArticle) + rssStar?.let { + it.description = body + appDb.rssStarDao.insert(it) + } + contentLiveData.postValue(body) } - contentLiveData.postValue(body) - } + } } fun favorite() {