pull/35/head^2
kunfei 5 years ago
parent 4356e9e30e
commit 26d040c39b
  1. 7
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  2. 1
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  3. 10
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -1,14 +1,17 @@
package io.legado.app.data.dao
import androidx.lifecycle.LiveData
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import io.legado.app.data.entities.RssArticle
interface RssArticleDao {
@Query("select * from rssArticles where origin = :origin")
@Query("select * from rssArticles where origin = :origin order by time desc")
fun liveByOrigin(origin: String): LiveData<List<RssArticle>>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssArticle: RssArticle)
}

@ -7,6 +7,7 @@ import androidx.room.PrimaryKey
@Entity(tableName = "rssArticles")
data class RssArticle(
var origin: String = "",
var time: Long = System.currentTimeMillis(),
@PrimaryKey
var guid: String? = null,
var title: String? = null,

@ -1,12 +1,20 @@
package io.legado.app.ui.rss.article
import android.app.Application
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.model.rss.RssParser
import java.net.URL
class RssArticlesViewModel(application: Application) : BaseViewModel(application) {
fun loadContent(url: String) {
execute {
val xml = URL(url).readText()
RssParser.parseXML(xml).let {
App.db.rssArtivleDao().insert(*it.toTypedArray())
}
}
}
}
Loading…
Cancel
Save