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 {