pull/42/head
kunfei 5 years ago
parent 8c66391703
commit 5ee320e440
  1. 4
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  2. 2
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  4. 6
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -7,8 +7,8 @@ import io.legado.app.data.entities.RssArticle
@Dao @Dao
interface RssArticleDao { interface RssArticleDao {
@Query("select * from rssArticles where origin = :origin and title = :title") @Query("select * from rssArticles where origin = :origin and link = :link")
fun get(origin: String, title: String): RssArticle? fun get(origin: String, link: String): RssArticle?
@Query("select * from rssArticles where origin = :origin order by `order` desc") @Query("select * from rssArticles where origin = :origin order by `order` desc")
fun liveByOrigin(origin: String): LiveData<List<RssArticle>> fun liveByOrigin(origin: String): LiveData<List<RssArticle>>

@ -6,7 +6,7 @@ import androidx.room.Ignore
@Entity( @Entity(
tableName = "rssArticles", tableName = "rssArticles",
primaryKeys = ["origin", "title"] primaryKeys = ["origin", "link"]
) )
data class RssArticle( data class RssArticle(
var origin: String = "", var origin: String = "",

@ -122,7 +122,7 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
viewModel.read(rssArticle) viewModel.read(rssArticle)
startActivity<ReadRssActivity>( startActivity<ReadRssActivity>(
Pair("origin", rssArticle.origin), Pair("origin", rssArticle.origin),
Pair("title", rssArticle.title) Pair("link", rssArticle.link)
) )
} }
} }

@ -20,13 +20,13 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) { fun initData(intent: Intent) {
execute { execute {
val origin = intent.getStringExtra("origin") val origin = intent.getStringExtra("origin")
val title = intent.getStringExtra("title") val link = intent.getStringExtra("link")
val rssSource = App.db.rssSourceDao().getByKey(origin) val rssSource = App.db.rssSourceDao().getByKey(origin)
rssSource?.let { rssSource?.let {
rssSourceLiveData.postValue(it) rssSourceLiveData.postValue(it)
} }
if (origin != null && title != null) { if (origin != null && link != null) {
App.db.rssArticleDao().get(origin, title)?.let { rssArticle -> App.db.rssArticleDao().get(origin, link)?.let { rssArticle ->
rssArticleLiveData.postValue(rssArticle) rssArticleLiveData.postValue(rssArticle)
if (!rssArticle.description.isNullOrBlank()) { if (!rssArticle.description.isNullOrBlank()) {
contentLiveData.postValue(rssArticle.description) contentLiveData.postValue(rssArticle.description)

Loading…
Cancel
Save