pull/49/head
kunfei 5 years ago
parent 74569f3fdd
commit 16b95a7017
  1. 14
      app/src/main/java/io/legado/app/data/entities/RssArticle.kt
  2. 20
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -19,6 +19,20 @@ data class RssArticle(
var read: Boolean = false
) {
override fun hashCode(): Int {
return super.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other == null) {
return false
}
if (other is RssArticle) {
return origin == other.origin && link == other.link
}
return false
}
fun toStar(): RssStar {
return RssStar(
origin = origin,

@ -72,17 +72,27 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
isLoading = true
val source = rssSource
val pageUrl = nextPageUrl
if (source != null && pageUrl != null) {
if (source != null && !pageUrl.isNullOrEmpty()) {
Rss.getArticles(source, pageUrl)
.onSuccess(IO) {
nextPageUrl = it?.nextPageUrl
it?.articles?.let { list ->
list.forEach { rssArticle ->
rssArticle.order = order--
if (list.isEmpty()) {
callBack?.loadFinally(false)
return@let
}
callBack?.adapter?.getItems()?.let { adapterItems ->
if (adapterItems.contains(list.first())) {
callBack?.loadFinally(false)
} else {
list.forEach { rssArticle ->
rssArticle.order = order--
}
App.db.rssArticleDao().insert(*list.toTypedArray())
}
}
App.db.rssArticleDao().insert(*list.toTypedArray())
isLoading = false
}
isLoading = false
}
} else {
callBack?.loadFinally(false)

Loading…
Cancel
Save