From 26d040c39b788c73c1fcb59be7775d97097b5066 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 2 Oct 2019 17:05:31 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/data/dao/RssArticleDao.kt | 7 +++++-- .../java/io/legado/app/data/entities/RssArticle.kt | 1 + .../legado/app/ui/rss/article/RssArticlesViewModel.kt | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) 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 5935d76ce..c90766948 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 @@ -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> - + @Insert(onConflict = OnConflictStrategy.REPLACE) + fun insert(vararg rssArticle: RssArticle) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt index 6f8773ba3..4f24761e3 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssArticle.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssArticle.kt @@ -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, diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 86894d3a4..9a1b904f0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -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()) + } + } } } \ No newline at end of file