From f1063bac0ece4fcc1d046d5bcacb75b37f87670f Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 9 Oct 2019 11:49:00 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 8 +++++++- .../legado/app/ui/rss/read/ReadRssViewModel.kt | 16 ++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 9640d501b..06551c8bf 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -20,7 +20,13 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r private fun initLiveData() { viewModel.contentLiveData.observe(this, Observer { - webView.loadData("$it", "text/html", "utf-8") + webView.loadDataWithBaseURL( + viewModel.rssArticle?.link, + "$it", + "text/html", + "utf-8", + viewModel.rssArticle?.link + ) }) viewModel.urlLiveData.observe(this, Observer { webView.loadUrl(it) 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 dcb363c9b..e1b4b85e8 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 @@ -11,7 +11,7 @@ import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.NetworkUtils class ReadRssViewModel(application: Application) : BaseViewModel(application) { - + var rssArticle: RssArticle? = null val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() @@ -20,8 +20,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { val origin = intent.getStringExtra("origin") val title = intent.getStringExtra("title") if (origin != null && title != null) { - val rssArticle = App.db.rssArtivleDao().get(origin, title) - if (rssArticle != null) { + rssArticle = App.db.rssArtivleDao().get(origin, title) + rssArticle?.let { rssArticle -> if (!rssArticle.description.isNullOrBlank()) { contentLiveData.postValue(rssArticle.description) } else { @@ -50,13 +50,13 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { rssArticle.link?.let { AnalyzeUrl(it, baseUrl = rssArticle.origin).getResponseAsync().await().body() ?.let { body -> - AnalyzeRule().apply { - setContent(body) - getString(ruleContent)?.let { content -> - contentLiveData.postValue(content) + AnalyzeRule().apply { + setContent(body) + getString(ruleContent)?.let { content -> + contentLiveData.postValue(content) + } } } - } } } }