From b02b7ffa0e6682bfa916d89848c5b180b20cc742 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 22:17:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/Debug.kt | 6 +++--- app/src/main/java/io/legado/app/model/Rss.kt | 7 +++++-- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 13 ++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 2acd8ac9e..51ae12afd 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -67,7 +67,7 @@ object Debug { if (ruleContent.isNullOrEmpty()) { log(debugSource, "⇒内容规则为空,默认获取整个网页", state = 1000) } else { - rssContentDebug(it.articles[0], ruleContent) + rssContentDebug(it.articles[0], ruleContent, rssSource) } } else { log(debugSource, "⇒存在描述规则,不解析内容页") @@ -80,9 +80,9 @@ object Debug { } } - private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String) { + private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String, rssSource: RssSource) { log(debugSource, "︾开始解析内容页") - Rss.getContent(rssArticle, ruleContent) + Rss.getContent(rssArticle, ruleContent, rssSource) .onSuccess { log(debugSource, it) log(debugSource, "︽内容页解析完成", state = 1000) diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index b4a4b5153..24dadade0 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -33,12 +33,15 @@ object Rss { fun getContent( rssArticle: RssArticle, ruleContent: String, + rssSource: RssSource?, scope: CoroutineScope = Coroutine.DEFAULT, context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - val body = AnalyzeUrl(rssArticle.link, baseUrl = rssArticle.origin) - .getResponseAwait(rssArticle.origin) + val body = AnalyzeUrl( + rssArticle.link, baseUrl = rssArticle.origin, + headerMapF = rssSource?.getHeaderMap() + ).getResponseAwait(rssArticle.origin) .body val analyzeRule = AnalyzeRule() analyzeRule.setContent( 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 cf8cafeef..f5b84642f 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 @@ -23,6 +23,7 @@ import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.isContentPath import io.legado.app.utils.writeBytes +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import java.io.File import java.util.* @@ -79,9 +80,15 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } private fun loadContent(rssArticle: RssArticle, ruleContent: String) { - Rss.getContent(rssArticle, ruleContent, this) - .onSuccess { - contentLiveData.postValue(it) + Rss.getContent(rssArticle, ruleContent, rssSource, this) + .onSuccess(IO) { body -> + rssArticle.description = body + App.db.rssArticleDao().insert(rssArticle) + rssStar?.let { + it.description = body + App.db.rssStarDao().insert(it) + } + contentLiveData.postValue(body) } }