pull/37/head
kunfei 5 years ago
parent 19cb9bd1fe
commit 0a6685c55d
  1. 3
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  2. 5
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  3. 20
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  4. 20
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -7,6 +7,9 @@ import io.legado.app.data.entities.RssArticle
@Dao @Dao
interface RssArticleDao { 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") @Query("select * from rssArticles where origin = :origin order by time desc")
fun liveByOrigin(origin: String): LiveData<List<RssArticle>> fun liveByOrigin(origin: String): LiveData<List<RssArticle>>

@ -62,9 +62,6 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
override fun readRss(rssArticle: RssArticle) { override fun readRss(rssArticle: RssArticle) {
viewModel.read(rssArticle) viewModel.read(rssArticle)
startActivity<ReadRssActivity>( startActivity<ReadRssActivity>(Pair("guid", rssArticle.guid))
Pair("description", rssArticle.description),
Pair("url", rssArticle.link)
)
} }
} }

@ -1,6 +1,7 @@
package io.legado.app.ui.rss.read package io.legado.app.ui.rss.read
import android.os.Bundle import android.os.Bundle
import androidx.lifecycle.Observer
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
@ -12,13 +13,18 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
get() = getViewModel(ReadRssViewModel::class.java) get() = getViewModel(ReadRssViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
val description = intent.getStringExtra("description") initLiveData()
val url = intent.getStringExtra("url") viewModel.initData(intent)
if (description.isNullOrBlank()) {
webView.loadUrl(url) }
} else {
webView.loadData("<style>img{max-width:100%}</style>$description", "text/html", "utf-8") private fun initLiveData() {
} viewModel.contentLiveData.observe(this, Observer {
webView.loadData("<style>img{max-width:100%}</style>$it", "text/html", "utf-8")
})
viewModel.urlLiveData.observe(this, Observer {
webView.loadUrl(it)
})
} }
} }

@ -1,8 +1,28 @@
package io.legado.app.ui.rss.read package io.legado.app.ui.rss.read
import android.app.Application import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
class ReadRssViewModel(application: Application) : BaseViewModel(application) { class ReadRssViewModel(application: Application) : BaseViewModel(application) {
val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<String>()
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)
}
}
}
}
}
} }
Loading…
Cancel
Save