diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index 0c6290965..fdcd309c8 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssArticle @Dao interface RssArticleDao { + @Query("select * from rssArticles where guid = :key") + fun get(key: String): RssArticle? + @Query("select * from rssArticles where origin = :origin order by time desc") fun liveByOrigin(origin: String): LiveData> diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 8ec14de5b..59eb5a77a 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -62,9 +62,6 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi override fun readRss(rssArticle: RssArticle) { viewModel.read(rssArticle) - startActivity( - Pair("description", rssArticle.description), - Pair("url", rssArticle.link) - ) + startActivity(Pair("guid", rssArticle.guid)) } } \ No newline at end of file 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 bece90c6c..9640d501b 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 @@ -1,6 +1,7 @@ package io.legado.app.ui.rss.read import android.os.Bundle +import androidx.lifecycle.Observer import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.utils.getViewModel @@ -12,13 +13,18 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r get() = getViewModel(ReadRssViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - val description = intent.getStringExtra("description") - val url = intent.getStringExtra("url") - if (description.isNullOrBlank()) { - webView.loadUrl(url) - } else { - webView.loadData("$description", "text/html", "utf-8") - } + initLiveData() + viewModel.initData(intent) + + } + + private fun initLiveData() { + viewModel.contentLiveData.observe(this, Observer { + webView.loadData("$it", "text/html", "utf-8") + }) + viewModel.urlLiveData.observe(this, Observer { + webView.loadUrl(it) + }) } } \ No newline at end of file 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 57874ef07..d1a7f3542 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 @@ -1,8 +1,28 @@ package io.legado.app.ui.rss.read import android.app.Application +import android.content.Intent +import androidx.lifecycle.MutableLiveData +import io.legado.app.App import io.legado.app.base.BaseViewModel class ReadRssViewModel(application: Application) : BaseViewModel(application) { + val contentLiveData = MutableLiveData() + val urlLiveData = MutableLiveData() + + fun initData(intent: Intent) { + execute { + intent.getStringExtra("guid")?.let { + val rssArticle = App.db.rssArtivleDao().get(it) + if (rssArticle != null) { + if (!rssArticle.description.isNullOrBlank()) { + contentLiveData.postValue(rssArticle.description) + } + } + } + } + + } + } \ No newline at end of file