feat: 优化代码

pull/182/head
kunfei 5 years ago
parent 9241b61c16
commit 49d1c9f40f
  1. 4
      app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt
  2. 2
      app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt
  3. 2
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -22,8 +22,8 @@ interface RssArticleDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg rssArticle: RssArticle) fun insert(vararg rssArticle: RssArticle)
@Query("delete from rssArticles where origin = :origin and `order` < :order") @Query("delete from rssArticles where origin = :origin and sort = :sort and `order` < :order")
fun clearOld(origin: String, order: Long) fun clearOld(origin: String, sort: String, order: Long)
@Update @Update
fun update(vararg rssArticle: RssArticle) fun update(vararg rssArticle: RssArticle)

@ -60,7 +60,7 @@ object RssParserByRule {
ruleTitle, rulePubDate, ruleDescription, ruleImage, ruleLink ruleTitle, rulePubDate, ruleDescription, ruleImage, ruleLink
)?.let { )?.let {
it.sort = sortName it.sort = sortName
it.origin = rssSource.sourceUrl it.origin = sourceUrl
articleList.add(it) articleList.add(it)
} }
} }

@ -39,7 +39,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
} }
App.db.rssArticleDao().insert(*list.toTypedArray()) App.db.rssArticleDao().insert(*list.toTypedArray())
if (!rssSource.ruleNextPage.isNullOrEmpty()) { if (!rssSource.ruleNextPage.isNullOrEmpty()) {
App.db.rssArticleDao().clearOld(rssSource.sourceUrl, order) App.db.rssArticleDao().clearOld(rssSource.sourceUrl, sortName, order)
loadFinally.postValue(true) loadFinally.postValue(true)
} else { } else {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {

Loading…
Cancel
Save