优化rss加载逻辑 (#4286)
This commit is contained in:
@@ -23,6 +23,9 @@ interface RssArticleDao {
|
|||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
fun insert(vararg rssArticle: RssArticle)
|
fun insert(vararg rssArticle: RssArticle)
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||||
|
fun append(vararg rssArticle: RssArticle)
|
||||||
|
|
||||||
@Query("delete from rssArticles where origin = :origin and sort = :sort and `order` < :order")
|
@Query("delete from rssArticles where origin = :origin and sort = :sort and `order` < :order")
|
||||||
fun clearOld(origin: String, sort: String, order: Long)
|
fun clearOld(origin: String, sort: String, order: Long)
|
||||||
|
|
||||||
|
|||||||
@@ -80,14 +80,16 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val firstArticle = articles.first()
|
val firstArticle = articles.first()
|
||||||
val dbArticle = appDb.rssArticleDao.get(firstArticle.origin, firstArticle.link)
|
val dbFirstArticle = appDb.rssArticleDao.get(firstArticle.origin, firstArticle.link)
|
||||||
if (dbArticle != null) {
|
val lastArticle = articles.last()
|
||||||
|
val dbLastArticle = appDb.rssArticleDao.get(lastArticle.origin, lastArticle.link)
|
||||||
|
if (dbFirstArticle != null && dbLastArticle != null) {
|
||||||
loadFinallyLiveData.postValue(false)
|
loadFinallyLiveData.postValue(false)
|
||||||
} else {
|
} else {
|
||||||
articles.forEach {
|
articles.forEach {
|
||||||
it.order = order--
|
it.order = order--
|
||||||
}
|
}
|
||||||
appDb.rssArticleDao.insert(*articles.toTypedArray())
|
appDb.rssArticleDao.append(*articles.toTypedArray())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user