From 21449396585eea61d96d5a41ddbf91c6e7b8fab0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 3 Oct 2019 13:49:14 +0800 Subject: [PATCH] up --- .../ui/rss/article/RssArticlesViewModel.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index a4ddecf4d..b2d052c29 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -4,9 +4,9 @@ import android.app.Application import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.rss.RssParser import io.legado.app.model.rss.RssParserByRule -import java.net.URL class RssArticlesViewModel(application: Application) : BaseViewModel(application) { @@ -19,14 +19,15 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application rssSource?.let { titleLiveData.postValue(rssSource.sourceName) } - val xml = URL(url).readText() - if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { - RssParser.parseXML(xml, url).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) - } - } else { - RssParserByRule.parseXML(xml, rssSource).let { - App.db.rssArtivleDao().insert(*it.toTypedArray()) + AnalyzeUrl(url).getResponseAsync().await().body()?.let { xml -> + if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { + RssParser.parseXML(xml, url).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } + } else { + RssParserByRule.parseXML(xml, rssSource).let { + App.db.rssArtivleDao().insert(*it.toTypedArray()) + } } } }.onFinally {