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. 14
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt

@ -19,6 +19,20 @@ data class RssArticle(
var read: Boolean = false 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 { fun toStar(): RssStar {
return RssStar( return RssStar(
origin = origin, origin = origin,

@ -72,18 +72,28 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
isLoading = true isLoading = true
val source = rssSource val source = rssSource
val pageUrl = nextPageUrl val pageUrl = nextPageUrl
if (source != null && pageUrl != null) { if (source != null && !pageUrl.isNullOrEmpty()) {
Rss.getArticles(source, pageUrl) Rss.getArticles(source, pageUrl)
.onSuccess(IO) { .onSuccess(IO) {
nextPageUrl = it?.nextPageUrl nextPageUrl = it?.nextPageUrl
it?.articles?.let { list -> it?.articles?.let { list ->
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 -> list.forEach { rssArticle ->
rssArticle.order = order-- rssArticle.order = order--
} }
App.db.rssArticleDao().insert(*list.toTypedArray()) App.db.rssArticleDao().insert(*list.toTypedArray())
isLoading = false
} }
} }
}
isLoading = false
}
} else { } else {
callBack?.loadFinally(false) callBack?.loadFinally(false)
} }

Loading…
Cancel
Save